how to measure angle between the lines?

I have plotted the lines with the following code.
x = [3 0];
y = [0 9];
line(x,y);
a = [1 2];
b = [0 3];
line(a,b);
axis([0 4 0 10]);
Now, how can I measure the angle between these lines?

댓글 수: 2

Jan
Jan 2013년 6월 6일
편집: Jan 2013년 6월 6일
The mathematical angle, the angle of the created lines in screen coordinates or the physical angle on the screen (while the last two are almost identical on modern flat screens, while they can differ substantially on arched CRT monitors)?
Do you want to "measure" the angle or to calculate it?
BV
BV 2013년 6월 6일
i wanted a way to calculate the angle.

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

 채택된 답변

Iain
Iain 2013년 6월 6일

1 개 추천

diff = (atan((y(2)-y(1))/(x(2)-x(1))) - atan((b(2)-b(1))/(a(2)-a(1)))) * 180/pi;

댓글 수: 5

BV
BV 2013년 6월 6일
편집: BV 2013년 6월 6일
thank u) so the difference what i get out of this('diff' code) is the angle?
Iain
Iain 2013년 6월 6일
편집: Iain 2013년 6월 6일
Yup
Angle1 = atan((y(2)-y(1))/(x(2)-x(1)))
Angle2 = atan((b(2)-b(1))/(a(2)-a(1)))
Are the angles each line makes to the x-axis. The difference is the angle between them in radians. *180/pi is the conversion to degrees.
Jan
Jan 2013년 6월 6일
diff() is an important Matlab command. Shadowing this name by using it as variable can lead to unexpected problems.
BV
BV 2013년 6월 6일
thank u very much.
MFB
MFB 2019년 4월 15일
편집: MFB 2019년 4월 15일
difference = (atan((y(2)-x(2))/(y(1)-x(1))) - atan((b(2)-a(2))/(b(1)-a(1)))) * 180/pi;
actually this will be the correct formula arrangement if you consider x as vector points and y as vector points making a line together and a and b making a line together. Algebraically, Jan gave correct formula to calculate angle difference. Thanks.

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

추가 답변 (1개)

Paul Kelly
Paul Kelly 2013년 6월 6일

0 개 추천

You can fit a straight line using polyval:
p = polyval(x, y, 1)
p(1) is the gradient and you can calculate the angle:
a = atan(p(1))
If you do this for each line you have two angles and can calculate the difference
Whether you mean measure or calculate (as per Jan's question) you will have to decide the coordinate system

댓글 수: 3

BV
BV 2013년 6월 6일
is there a way to plot these lines in 3D?
Iain
Iain 2013년 6월 6일
"plot3" is a function that lets you plot lines in 3D.
If you are trying to find the angle between two lines, in a 3D space, then my solution is NOT the one you want. Mine only works for coplanar lines and an axis set that matches that plane.
benedikta siboro
benedikta siboro 2018년 5월 8일
I want to measure angle of human body using GUI.how i can measure?

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

카테고리

태그

질문:

BV
2013년 6월 6일

편집:

MFB
2019년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by