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 CenterFile Exchange에서 Read, 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