How to find angle between two lines?

조회 수: 162 (최근 30일)
Beulah A
Beulah A 2019년 10월 21일
이동: Dyuman Joshi 2024년 1월 9일
For example, there is line L1 between two points (x1,y1) and (x2,y2). Another line L2 between points (x1,y1) and (x3,y3). I want to find the angle between the lines L1, L2. How to find in MATLAB? I think in matlab there is no predefined function which performs the same.
  댓글 수: 2
sudeep
sudeep 2024년 1월 7일
이동: Dyuman Joshi 2024년 1월 9일
TURE AND
Example 1: Find the angle between r1 = 2(1 + cost) and r23(1-cost) and plot the graph for the same.

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

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 10월 21일
A more stable method that what Jos suggested is
v_1 = [x2,y2,0] - [x1,y1,0];
v_2 = [x3,y3,0] - [x1,y1,0];
Theta = atan2(norm(cross(v_1, v_2)), dot(v_1, v_2));
HTH
  댓글 수: 3
jari jafri
jari jafri 2023년 10월 4일
편집: jari jafri 2023년 10월 4일
I got my V_1 and V_2 vectors as
v_1 =
1×3 int32 row vector
-633 990 0
v_2 =
1×3 int32 row vector
0 500 0
But i am having the following error so I 'm looking for how to remove this error
Error using norm
First argument must be single or double.
Error in test6 (line 64)
Theta = atan2(norm(cross(v_1, v_2)), dot(v_1, v_2));
I'm getting this error while using this code
Dyuman Joshi
Dyuman Joshi 2023년 10월 4일
@jari jafri convert the data to double -
v_1 = int32([-633 990 0]);
v_2 = int32([0 500 0]);
v_1 = double(v_1);
v_2 = double(v_2);
Theta = atan2(norm(cross(v_1, v_2)), dot(v_1, v_2))
Theta = 0.5689

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

추가 답변 (2개)

Jos (10584)
Jos (10584) 2019년 10월 21일
Use the dot product between the two vectors (v1 and v2) given by the four x,y pairs points.
Given the formula: dot(v1,v2) = | v1 | x | v2 | x cos(A)
I leave it to you to find the angle A using the matlab functions norm, dot and acos.

Bjorn Gustavsson
Bjorn Gustavsson 2019년 10월 21일

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by