/* (c) 2013 Nicolaus Anderson */ #include #ifndef _CIRCLE2D_ #define _CIRCLE2D_ namespace irr { namespace core { //! Class circle 2D /* A 2D circle. */ template class circle2d { public: vector2d center; T radius; circle2d() : radius( (T)0 ) {} circle2d( T x, T y, T r ) : center( vector2d(x,y) ) , radius( r ) {} circle2d( vector2d origin, T r ) : center( origin ) , radius( r ) {} //! Set void set( T x, T y, T r ) { center = vector2d(x,y); radius = r; } //! Set void set( vector2d origin, T r ) { center = origin; radius = r; } //! Top point /* Returns a vector that gives the top-most point on the circle. */ vector2d topPoint() { return vector2d( center.X, center.Y + radius); } //! Get area T getArea() { return PI * radius * radius; } //! Circumference inline T getCircumference() { return 2 * PI * radius; } //! Point inside? bool isPointInside( vector2d point ) { return ( point - center ).getLengthSQ() <= radius * radius; } //! Get horizon /* Returns the horizontal secant line of the circle at the given distance from the top. The line goes from the left side of the circle to the right side. */ line2d getHorizon( T distDown ) { line2d ret; ret.start.Y = center.Y + radius - distDown; ret.end.Y = ret.start.Y; ret.end.X = (T) squareroot( (irr::f64) ( radius * radius ) - ret.start.Y ); ret.start.X = - ret.end.X; // get the negative of the sqrt // correct origin offset ret.start.X += center.X; ret.end.X += center.X; return ret; } }; typedef circle2d circle2di; typedef circle2d circle2df; } // end namespace core } // end namespace irr #endif // #ifndef _CIRCLE2D_