Change the zero angle of the atan2() or similar

10 Ansichten (letzte 30 Tage)
HecLondon
HecLondon am 18 Sep. 2013
Beantwortet: theodore panagos am 15 Jan. 2019
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 Kommentar
Muthu Annamalai
Muthu Annamalai am 18 Sep. 2013
As @John points out, adding a post-atan2 offset should do the trick, and give you what you're looking for.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

John Petersen
John Petersen am 18 Sep. 2013
Add an offset to the angle. Let the offset be the starting angle.

Roger Stafford
Roger Stafford am 18 Sep. 2013
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 am 15 Jan. 2019
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)))

Community Treasure Hunt

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

Start Hunting!

Translated by