필터 지우기
필터 지우기

How can I get then angle between a line connecting two points in the plot and a vector (with only direction specified)?

조회 수: 2 (최근 30일)
As you can see above, I have x and y co-ordinates for n number of Wind Turbines in a wind farm. Suppose there is a vector (wind speed direction) with direction in degrees, how do i find the angle between the line connecting all the other points to any point i,j in the x-y plane and the direction vector (whose onlyu data known is the direction?
xy=[0 0
0 800
0 1600
0 2400
500 0
500 800
500 1600
500 2400
1000 0
1000 800
1000 1600
1000 2400
1500 0
1500 800
1500 1600
1500 2400
2000 0
2000 800
2000 1600
2000 2400];
The above matrix shows the x-y coordiantes of 20 points in the x-y plane.
I need the angle between the line connecting point 1 to all other 19 points and a vector with a direction (say 45 degrees).

채택된 답변

Ruben Costa
Ruben Costa 2019년 7월 10일
Hi, my aproach is here!
xy=[0 0
0 800
0 1600
0 2400
500 0
500 800
500 1600
500 2400
1000 0
1000 800
1000 1600
1000 2400
1500 0
1500 800
1500 1600
1500 2400
2000 0
2000 800
2000 1600
2000 2400]; %This is your matrix with the points
angle=[]; %this is where the angles will be stored
for i=2:size(xy,1)
nline=i-1;
angle(nline) = (atan((xy(i,2)-xy(1,2))/(xy(i,1)-xy(1,1))) - atan((2-0)/(2-0))) * 180/pi;
end
- (xy(i,2)-xy(1,2))/(xy(i,1)-xy(1,1)) ---> this is the value of the tangent of the line created with the point (0,0) and other point of the matrix xy
- (2-0)/(2-0)) ---> this is the value of the tangent of the line created with the point (0,0) and point (2,2) because i knew that this line would have 45º
Then I calculated the arctan( the angles) of both and subtracted to know the angle between them. Then I only made the conversion from radians to degrees!
Hope it helps!

추가 답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2019년 7월 10일
Best way to go about this is to convert the "wind"-direction to a wind-vector, then use:
w_angle = atan2(norm(cross(wv,b)), dot(wv,b));
Where b is the vector between your points.
HTH
  댓글 수: 2
Sooraj Narayan
Sooraj Narayan 2019년 7월 10일
Thanks for the answer.
Just to continue on your comment, what do you mean by converrting the 'direction' to a 'vector'? What would be the vector corresponding to the direction, say 45 degrees?
Bjorn Gustavsson
Bjorn Gustavsson 2019년 7월 10일
It would depend on the convention for your wind-direction, lets say we use the mathematical notation with phi_w counterclockwise from East, then, with x-component in the Easterly direction, y towards north:
wv = [cos(phi_w), sin(phi_w) 0];

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

카테고리

Help CenterFile Exchange에서 Vehicle Scenarios에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by