JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Finding a signed angle | Reply
Here is a better algorithm for finding a signed angle between two line segments with a common starting point where the angle is measured counter-clockwise from 0 to +/- pi.
double sX, sY; //the common starting point
double aX, aY, bX, bY; //the two points radiating from sX,sY
...
//using C# Math.Atan2(y,x) method:
double dRad1 = Math.Atan2(aY-sY,aX-sX);
double dRad2 = Math.Atan2(bY-sY,bX-sX);
double dRad = dRad2 - dRad1;


note: angles > pi are shown as (pi - angle)
Re: Finding a signed angle (response to post by dran001) | Reply
Trig way that I have an easier time remembering:
dRad = Math.atan2(Math.sin(dRad), Math.cos(dRad));

Probably faster way:
dRad = (dRad+Math.PI)%(Math.PI*2)-Math.PI;
Re: Finding a signed angle (response to post by dran001) | Reply
If aX == sX or bX == sX, then we would have a division by zero, right? What to do in this case?
Re: Finding a signed angle (response to post by elcabezon) | Reply
Note that atan2() takes two arguments: y and x, not one argument y/x. There is no division by zero. See man atan2 for more detail.
Re: Finding a signed angle (response to post by misof) | Reply
OK thanks
Re: Finding a signed angle (response to post by misof) | Reply
Is there a way to see the source code of these trigonometric functions? I've looked in /usr/include/math.h but I can't find it.
Re: Finding a signed angle (response to post by wack-a-mole) | Reply
www.google.com/codesearch?q=\satan2\([^\)]*\)\s*{

edit: Just copy the whole link, I can`t get it to work on this forum.
edit2: sorry, the results are not that good
Re: Finding a signed angle (response to post by maniek) | Reply
Still , We don't have actual code.
RSS