calculate the angle between a line (between two points) and the perpendicular line

조회 수: 4 (최근 30일)
if point1 is a(x1,y1) and point 2 is b(x2,y2). I want to draw a vertical from point b in order to calculate the angle between the line ab and the verticle line.
I wrote this code but I think i can't get the verticle line correctly as I got the same value of the angle and i'm sure the angle value is not the same.
for i=1:size(a,1)
angle = atand(b(1,i) - a(1,i))-(b(2,i) - a(2,i)))
end
any one can help me please?
Clipboard-1.png
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2019년 3월 20일
Amneh's answer moved here
I'm using a loop because points a and b are moving and changing their positions. I want to caluctae the angle for every fram. I assumed that the vericle line is between (point a (x1,y1) and Point (x1,y2))
Geoff Hayes
Geoff Hayes 2019년 3월 20일
I assumed that the vericle line is between (point a (x1,y1) and Point (x1,y2)) Can you provide a picture? I don't understand how the vertical line is between (x1,y1) and (x1,y2) (or do you mean (x2,y2) for the second one?). Also I thought I want to draw a vertical from point b which suggests that the vertical line is drawn from point b and is not in between the two points. Please clarify.

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

채택된 답변

Jan
Jan 2019년 3월 20일
Maybe you mean:
angle = atand(b(1,:) - a(1,:)) - (b(2,:) - a(2,:)))
% ^???
without a loop. But here the number of parentheses does not match. I'm not sure which problem you want to solve.

추가 답변 (2개)

Geoff Hayes
Geoff Hayes 2019년 3월 20일
편집: Geoff Hayes 2019년 3월 20일
Amneh - if a is (x1,y1) and b is (x2,y2) then let c be (x2,y1). With these three points, you should have a right-angled triangle. We can determine the opposite and adjancent as
opposite = abs(a(1) - c(1));
adjacent = abs(c(2) - b(2));
and so the angle is
myAngleDegrees = atand(opposite / adjacent);
(I think!)

Amneh Alshawabka
Amneh Alshawabka 2019년 3월 20일
Thanks alot for your help . I'm a new Matlab user.
Actually i'm not sure how to creat a vertical line either from point a or b!! I want to caculate the angle between line ab and the verticale line from b to the ground as shown in the picture below.
  댓글 수: 1
Jan
Jan 2019년 3월 20일
편집: Jan 2019년 3월 20일
Please post comments in the section for comments. The best location for the picture is the original question, where readers expect the full information (I've inserted it there).

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

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by