summaryrefslogtreecommitdiffstats
path: root/src/math/point.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/point.h')
-rw-r--r--src/math/point.h131
1 files changed, 2 insertions, 129 deletions
diff --git a/src/math/point.h b/src/math/point.h
index 7000138..fdb3051 100644
--- a/src/math/point.h
+++ b/src/math/point.h
@@ -70,7 +70,7 @@ struct Point
//! Returns the distance from (0,0) to the point (x,y)
inline float Length()
{
- return sqrt(x*x + y*y);
+ return sqrtf(x*x + y*y);
}
//! Returns the inverted point
@@ -163,134 +163,7 @@ inline void Swap(Point &a, Point &b)
//! Returns the distance between two points
inline float Distance(const Point &a, const Point &b)
{
- return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
-}
-
-//! Returns py up on the line \a a - \a b
-inline float MidPoint(const Point &a, const Point &b, float px)
-{
- if (IsEqual(a.x, b.x))
- {
- if (a.y < b.y)
- return HUGE;
- else
- return -HUGE;
- }
- return (b.y-a.y) * (px-a.x) / (b.x-a.x) + a.y;
-}
-
-//! Calculates the parameters a and b of the linear function passing through \a p1 and \a p2
-/** Returns \c false if the line is vertical.
- \param p1,p2 points
- \param a,b linear function parameters */
-inline bool LinearFunction(const Point &p1, const Point &p2, float &a, float &b)
-{
- if ( IsZero(p1.x-p2.x) )
- {
- a = HUGE;
- b = p2.x;
- return false;
- }
-
- a = (p2.y-p1.y) / (p2.x-p1.x);
- b = p2.y - p2.x*a;
-
- return true;
-}
-
-//! Checks if the point is inside triangle defined by vertices \a a, \a b, \a c
-inline bool IsInsideTriangle(Point a, Point b, Point c, const Point &p)
-{
- if ( p.x < a.x && p.x < b.x && p.x < c.x ) return false;
- if ( p.x > a.x && p.x > b.x && p.x > c.x ) return false;
- if ( p.y < a.y && p.y < b.y && p.y < c.y ) return false;
- if ( p.y > a.y && p.y > b.y && p.y > c.y ) return false;
-
- if ( a.x > b.x ) Swap(a,b);
- if ( a.x > c.x ) Swap(a,c);
- if ( c.x < a.x ) Swap(c,a);
- if ( c.x < b.x ) Swap(c,b);
-
- float n, m;
-
- n = MidPoint(a, b, p.x);
- m = MidPoint(a, c, p.x);
- if ( (n>p.y || p.y>m) && (n<p.y || p.y<m) )
- return false;
-
- n = MidPoint(c, b, p.x);
- m = MidPoint(c, a, p.x);
- if ( (n>p.y || p.y>m) && (n<p.y || p.y<m) )
- return false;
-
- return true;
-}
-
-//! Rotates a point around a center
-/** \a center center of rotation
- \a angle angle is in radians (positive is counterclockwise (CCW) )
- \a p the point */
-inline Point RotatePoint(const Point &center, float angle, const Point &p)
-{
- Point a;
- a.x = p.x-center.x;
- a.y = p.y-center.y;
-
- Point b;
- b.x = a.x*cosf(angle) - a.y*sinf(angle);
- b.y = a.x*sinf(angle) + a.y*cosf(angle);
-
- b.x += center.x;
- b.y += center.y;
-
- return b;
-}
-
-//! Rotates a point around the origin (0,0)
-/** \a angle angle in radians (positive is counterclockwise (CCW) )
- \a p the point */
-inline Point RotatePoint(float angle, const Point &p)
-{
- float x = p.x*cosf(angle) - p.y*sinf(angle);
- float y = p.x*sinf(angle) + p.y*cosf(angle);
-
- return Point(x, y);
-}
-
-//! Rotates a vector (dist, 0).
-/** \a angle angle is in radians (positive is counterclockwise (CCW) )
- \a dist distance to origin */
-inline Point RotatePoint(float angle, float dist)
-{
- float x = dist*cosf(angle);
- float y = dist*sinf(angle);
-
- return Point(x, y);
-}
-
-//! Calculates the angle between two points and one center
-/** \a center the center point
- \a p1,p2 the two points
- \returns The angle in radians (positive is counterclockwise (CCW) ) */
-inline float RotateAngle(const Point &center, const Point &p1, const Point &p2)
-{
- if (PointsEqual(p1, center))
- return 0;
-
- if (PointsEqual(p2, center))
- return 0;
-
- float a1 = asinf((p1.y - center.y) / Distance(p1, center));
- float a2 = asinf((p2.y - center.y) / Distance(p2, center));
-
- if (p1.x < center.x) a1 = PI - a1;
- if (p2.x < center.x) a2 = PI - a2;
-
- float a = a2 - a1;
- if (a < 0)
- a += PI_MUL_2;
-
- return a;
+ return sqrtf((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}
/* @} */ // end of group