Change the zero angle of the atan2() or similar

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 个评论

As @John points out, adding a post-atan2 offset should do the trick, and give you what you're looking for.

请先登录,再进行评论。

回答(3 个)

Add an offset to the angle. Let the offset be the starting angle.
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.
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)))

类别

帮助中心File Exchange 中查找有关 Geometric Transformation and Image Registration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by