Change the zero angle of the atan2() or similar

2 ビュー (過去 30 日間)
HecLondon
HecLondon 2013 年 9 月 18 日
回答済み: theodore panagos 2019 年 1 月 15 日
Hello,
I have a group of points in an image and I want to order them/get properties in a clockwise direction. The condition to order them will be their angle.
I need to choose the starting point, with angle 0, and then the other points in a clockwise order (increasing angle). However, I am using the atan2 (2 because the range of angles in better) to get the angles, but the zero angle is always in the horizontal axis. How can I set the axis of the zero angle to be in the location of the starting point?
Many thanks! Hector
  1 件のコメント
Muthu Annamalai
Muthu Annamalai 2013 年 9 月 18 日
As @John points out, adding a post-atan2 offset should do the trick, and give you what you're looking for.

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

回答 (3 件)

John Petersen
John Petersen 2013 年 9 月 18 日
Add an offset to the angle. Let the offset be the starting angle.

Roger Stafford
Roger Stafford 2013 年 9 月 18 日
If you want the order to be clockwise and if (x0,y0) is the start point then do this:
ang = mod(atan2(y0,x0)-atan2(y,x),2*pi);
where (x,y) are the points to be ordered - they can be vectors. These angles will be in radians. The subtraction is necessary because the natural order in 'atan2' is counterclockwise. The 'mod' function is necessary to ensure that the range of 'ang' remains between 0 and 2*pi.

theodore panagos
theodore panagos 2019 年 1 月 15 日
The formula give a clockwise angle, from 0 to 2pi.
f(x,y)=pi()/2*((1+sign(y0))* (1-sign(x0^2))-(1+sign(y))* (1-sign(x^2)))+pi()/4*((2+sign(y0))*sign(x0)-(2+sign(y))*sign(x))
+sign(x0*y0)*atan((abs(y0)-abs(x0))/(abs(y0)+abs(x0)))-sign(x*y)*atan((abs(y)-abs(x))/(abs(y)+abs(x)))

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by