[Home]History of Synnalagma/Utils

Robo Home | Changes | Preferences | AllPages


Revision 10 . . (edit) May 6, 2004 2:18 EST by Filmil
Revision 8 . . October 23, 2003 13:58 EST by Synnalagma
  

Difference (from prior major revision) (minor diff)

Changed: 202c202,222
Math.IEEERemainder is in fact normalizeAngle just do Math.IEEERemainder(angle,2*Math.PI). --Synnalagma
Math.IEEERemainder is in fact normalizeAngle just do Math.IEEERemainder(angle,2*Math.PI). --Synnalagma

Solving the problem in a direct way.

/** Note: you need an appropriate implementation of the functions mentioned here. Also
* note that zero heading vector and its normal could be hardcoded if needed. For the sake of
* example, let's not do that here.
* @param angle The angle to be normalized
* @return Normalized angle value, in the range (-PI, PI]
*/
public double absoluteAngle(double angle) {
Vector unit = Math.unitvec(angle); // get the unit vector with angle as bearing
Vector zero = Math.unitvec(0); // get the vector with angle 0
Vector norm = Math.getNormal(zero);// get the normal to unit, rotated in positive direction
double cosangle = Math.cosangle(unit,zero); // get the cosine of the angle, using dot product
int sign = Math.sign( Math.dot(unit, norm) );
double absangle = sign * java.lang.Math.acos(cosangle);
return absangle;
}

Using dot product etc is quite a good way to do away with awkward angle normalization. I have not seen that using classes such as Vector and more operations slow things down. -- filmil

Robo Home | Changes | Preferences | AllPages
Search: