how to find concave angle between three points

Hello how can I fing agle if I know three points, but I would like to reald also the concave one.
this function ang = atan2(norm(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0)); , it gives me only convex one
thank you

댓글 수: 14

Torsten
Torsten 2022년 11월 22일
May I ask what you mean by convex and concave angle ?
Sure, so the matlab gives me values 10, 30, 50 ... 180 degree and than (because it is circle it has 360 degrees) but matlab when it turns 180 it goes 170, 160 ... until 0
but I would like to go 180, 190 .. until 360
Torsten
Torsten 2022년 11월 22일
Could you show reproducable code ?
for f=1:h
t=(f-1)*k/20;
m=f+1;
P0=[70 70]; %střed [x,y]
P1=[htabulka(1,1),htabulka(1,2)]; %XY1 [x,y]
P2=[htabulka(f,1),htabulka(f,2)]; %XY2 [x,y]
angstn = unwrap(atan2(norm(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0)));
ang=angstn*180/pi
cosf=cos(ang);
Torsten
Torsten 2022년 11월 22일
We cannot run this code since h, k, htabula are not known.
h is 219 and k is 500
But you can not run it because .. this code is connect with the another code where I use video ...
I send you the output
see it goes to 178 and than it suppose the be greater than 180 .. but it goes down
Torsten
Torsten 2022년 11월 22일
We still don't know htabulka.
I give you the output ... I can not give you the whole code it is large and you need the video I use
I cannot tell you more than using
P1(1) = 3;
P1(2) = 5;
P2(1) = 7;
P2(2) = -8;
P3(1) = 4;
P3(2) = 4;
angle = (atan2(P3(2) - P1(2), P3(1) - P1(1)) - atan2(P2(2) - P1(2), P2(1) - P1(1)))*180/pi
angle = 27.8973
if angle < 0
angle = angle + 360;
end
hold on
plot([P1(1);P2(1)],[P1(2);P2(2)])
plot([P1(1);P3(1)],[P1(2);P3(2)])
hold off
DGM
DGM 2022년 11월 22일
편집: DGM 2022년 11월 22일
On behalf of OP, here is a MWE:
thd = 0:10:360; % a sequence of angles from 0-360
xx = cosd(thd);
yy = sind(thd);
h = numel(thd);
ang = zeros(h,1);
for f = 1:h
P0=[0 0]; % some fixed point
P1=[1 0]; % i'm going to fix this one too
P2=[xx(f) yy(f)]; % this point moves in a circle about P0 [x,y]
angstn = unwrap(atan2(norm(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0)));
ang(f) = angstn*180/pi;
end
cosf = cos(ang);
plot(thd,ang) % output is folded at 180
... but that kind of makes sense, if we're always looking for the interior angle.
Let the OP choose what better fits her needs:
thd = 0:10:360; % a sequence of angles from 0-360
xx = cosd(thd);
yy = sind(thd);
h = numel(thd);
ang = zeros(h,1);
for f = 1:h
P1=[0 0]; % some fixed point
P2=[1 0]; % i'm going to fix this one too
P3=[xx(f) yy(f)]; % this point moves in a circle about P0 [x,y]
angstn = atan2(P3(2) - P1(2), P3(1) - P1(1)) - atan2(P2(2) - P1(2), P2(1) - P1(1));
if angstn < 0
angstn = angstn + 2*pi;
end
ang(f) = angstn*180/pi;
end
cosf = cos(ang);
plot(thd,ang) % output is folded at 180
Thank you so much
It means a lot for me
thank you

댓글을 달려면 로그인하십시오.

답변 (1개)

David Goodmanson
David Goodmanson 2022년 11월 23일

0 개 추천

Hi Eliska,
One thing that does not seem to be mentioned so far is your use of the norm function on the determinant. That makes all the sines positive, which puts you into the first or second quadrant and forces all the angles out of atan2d to be 0<=theta<180. Dropping the norm opens up the range of angles to 0<=theta<360. In the code below, (P2-P0) is a reference vector, and the angle is measured counterclockwise from (P2-P0) to (P1-P0) with 0<=theta<360.
P0 = [0 0];
P1 = [-1 2];
P2 = [1 1];
P20 = P2-P0; % reference vector
P10 = P1-P0;
theta = atan2d((det([P20;P10])),dot(P20,P10));
theta = mod(theta,360)

카테고리

도움말 센터File Exchange에서 Multibody Dynamics에 대해 자세히 알아보기

태그

질문:

2022년 11월 22일

답변:

2022년 11월 23일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by