many changes :P
This commit is contained in:
24
geo/Angle.h
24
geo/Angle.h
@@ -2,20 +2,34 @@
|
||||
#define ANGLE_H
|
||||
|
||||
#include <cmath>
|
||||
#include <KLib/Assertions.h>
|
||||
|
||||
class Angle {
|
||||
|
||||
public:
|
||||
|
||||
/** get the radians from (x1,y1) to (x2,y2) */
|
||||
static float getRAD(const float x1, const float y1, const float x2, const float y2) {
|
||||
/** get the radians from (x1,y1) to (x2,y2) between 0 (to-the-right) and <2_PI */
|
||||
static float getRAD_2PI(const float x1, const float y1, const float x2, const float y2) {
|
||||
_assertFalse( (x1==x2)&&(y1==y2), "(x1,y1) must not equal (x2,y2)!!");
|
||||
const float tmp = std::atan2(y2-y1, x2-x1);
|
||||
return (tmp < 0) ? (tmp + 2*M_PI) : (tmp);
|
||||
}
|
||||
|
||||
/** get the degrees from (x1,y1) to (x2,y2) */
|
||||
static float getDEG(const float x1, const float y1, const float x2, const float y2) {
|
||||
return radToDeg(getRAD(x1,y1,x2,y2));
|
||||
/** get the degrees from (x1,y1) to (x2,y2) between 0 (to-the-right) and <360 */
|
||||
static float getDEG_360(const float x1, const float y1, const float x2, const float y2) {
|
||||
return radToDeg(getRAD_2PI(x1,y1,x2,y2));
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the angular difference between
|
||||
* - the given radians [0:2PI]
|
||||
* - as a change-in-direction between [0:PI]
|
||||
*/
|
||||
static float getDiffRAD_2PI_PI(const float r1, const float r2) {
|
||||
_assertBetween(r1, 0, 2*M_PI, "r1 out of bounds");
|
||||
_assertBetween(r2, 0, 2*M_PI, "r2 out of bounds");
|
||||
return fmod(std::abs(r2 - r1), M_PI);
|
||||
|
||||
}
|
||||
|
||||
/** convert degrees to radians */
|
||||
|
||||
Reference in New Issue
Block a user