Angle between a vector and a line parallel with the y-axis? (image example)

Hi, I have this red point with coordinates (x1,y1) and I would like to calculate the angles that each vector departing from the red point to the black ones form with a line parallel to the y-axis. How should I do? I'm so sorry for the drawing but that is exactly the scenario. Thanks!

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 3 日
Try something like this
P = [-3, 5]; % (x1,y1)
x = [0 10]; % point of y-axis
Px = x-P;
angle = atan2(Px(1), -Px(2))

6 件のコメント

Davide Mori
Davide Mori 2020 年 11 月 3 日
why is there -Px(2) in the atan2 function?
Ameer Hamza
Ameer Hamza 2020 年 11 月 3 日
y-axis is negative in a downward direction, whereas we want a positive x-axis in the downward direction in our rotated coordinates.
Davide Mori
Davide Mori 2020 年 11 月 3 日
I was checking your solution with different values. Let's put
p = [-3 0.95]
r = [0 0] %point on the origin of axis
pr = r - p
angle = atan2(pr(1), -pr(2))
Now, I would expect an angle which is less than 90 degrees but converting instead I obtain -107 degrees, why this?
Ameer Hamza
Ameer Hamza 2020 年 11 月 3 日
I get expected answer. atan2() return the output in radians. How did you get -107 from that. When I run the following code
p = [-3 0.95]
r = [0 0] %point on the origin of axis
pr = r - p
angle = atan2(pr(1), -pr(2))
I get
>> angle
angle =
1.2641
>> rad2deg(angle)
ans =
72.4287
It might be easier to use atan2d()
p = [-3 0.95]
r = [0 0] %point on the origin of axis
pr = r - p
angle = atan2d(pr(1), -pr(2))
Result
>> angle
angle =
72.4287
Davide Mori
Davide Mori 2020 年 11 月 4 日
You are right, I don't know I got that result ahahah, thank you so much!
Ameer Hamza
Ameer Hamza 2020 年 11 月 4 日
I am glad to be of help! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractions, Camera Views, and Lighting についてさらに検索

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by