Ellipse_t Class Reference

Class representing an ellipse in a 2 dimensional coordinate space. More...

#include <UTGeometry.h>

List of all members.

Public Member Functions

 Ellipse_t ()
 Ellipse_t (const Point_t &center, float width, float height, double rotation)
 Ellipse_t (const Ellipse_t &copy)
void Set (const Point_t &center, float width, float height, double rotation)
Point_t Center () const
void GetCenter (out Point_t *center) const
float Width () const
float Height () const
double Rotation () const
const Ellipse_toperator= (const Ellipse_t &copy)
Ellipse_t operator+ (const Point_t &add) const
Ellipse_t operator- (const Point_t &subtract) const
const Ellipse_toperator+= (const Point_t &add)
const Ellipse_toperator-= (const Point_t &subtract)
bool Contains (const Point_t &point) const
bool Overlapping (const Rect_t &rect) const
Rect_t BoundingBox () const
void GetBoundingBox (out Rect_t *bounding_box, out double *t_left=NULL, out double *t_top=NULL, out double *t_right=NULL, out double *t_bottom=NULL) const
void GetPointAndSlopeAtT (double t, out Point_t *point_on_ellipse, out double *slope=NULL) const
int FindXIntercepts (float y, out float *x, out double *t=NULL, out double *slope=NULL) const
int FindYIntercepts (float x, out float *y, out double *t=NULL, out double *slope=NULL) const
void FindClosestPoint (const Point_t &from, bool on_edge_if_inside, out Point_t *closest_point_on_ellipse, out double *t=NULL, out double *slope=NULL) const
void Rotate (double radians)
void RotateAbout (double radians, const Point_t &point)

Detailed Description

Class representing an ellipse in a 2 dimensional coordinate space. Although it can be used in other ways, the value space which is typically used is that for a monitor, with increasing x values to the right and increasing y values to the bottom. The following documentation assumes that coordinate space polarity. Floating point numbers are used by the UTgfx and UTgui libraries to represent screen display because for scaling, use of floating point computation until final conversion to an integer coordinate is more efficient than use of integers. That way the same interface can be used to render to the display, printer, and so on. Floats are accurate to within c_dbl_abs_min_denominator out to about 4,000,000.

The parametric form of the equation for an ellipse is used, where t is the parametric value in radians. Radian value zero is the top of the ellipse, with increasing radian values going clockwise.

    x = sin(t) * width/2
    y = -cos(t) * height/2
    

The locations of t are as follows:

    t=0: top edge
    t=pi/2: right edge
    t=pi: bottom edge
    t=3*pi/2: left edge
    

From there, the ellipse can be rotated, with increasing positive rotation values represent clockwise rotation, with pi/2 being rotation by ninty degrees. The equations for rotation about the origin are:

    x' = x*cos(r) - y*sin(r)
    y' = y*cos(r) + x*sin(r)
    

So the equation of the rotated ellipse is:

    x = sin(t) * (width/2)*cos(r) + cos(t) * (height/2)*sin(r)
    y = sin(t) * (width/2)*sin(r) - cos(t) * (height/2)*cos(r)
    

From there, the ellipse is offset such that the equations above are offset to be around a center point. The final equation, covering all properties of the ellipse is:

    x = center.x + sin(t) * (width/2)*cos(r) + cos(t) * (height/2)*sin(r)
    y = center.y + sin(t) * (width/2)*sin(r) - cos(t) * (height/2)*cos(r)
    

Definition at line 766 of file UTGeometry.h.


Constructor & Destructor Documentation

Ellipse_t::Ellipse_t (  )  [inline]

Constructor.

Definition at line 1785 of file UTGeometry.h.

Ellipse_t::Ellipse_t ( const Point_t center,
float  width,
float  height,
double  rotation 
)

Initializer for a new ellipse with the specified properties. Width and height are only truly the width and height if rotation is zero. Rotation is specified in radians, and increasing values represent clockwise rotation.

Ellipse_t::Ellipse_t ( const Ellipse_t copy  ) 

Copy constructor.


Member Function Documentation

void Ellipse_t::Set ( const Point_t center,
float  width,
float  height,
double  rotation 
)

Sets the properties of the ellipse.

Point_t Ellipse_t::Center (  )  const [inline]

Returns the center of the ellipse.

Definition at line 1798 of file UTGeometry.h.

void Ellipse_t::GetCenter ( out Point_t center  )  const [inline]

Returns the center of the ellipse.

Definition at line 1805 of file UTGeometry.h.

float Ellipse_t::Width (  )  const [inline]

Returns the width of the ellipse if it is not rotated.

Definition at line 1812 of file UTGeometry.h.

float Ellipse_t::Height (  )  const [inline]

Returns the height of the ellipse if it is not rotated.

Definition at line 1819 of file UTGeometry.h.

double Ellipse_t::Rotation (  )  const [inline]

Returns the rotation of the ellipse, in radians, with increasing values representing clockwise rotation.

Definition at line 1826 of file UTGeometry.h.

const Ellipse_t& Ellipse_t::operator= ( const Ellipse_t copy  ) 

Assignment operator.

Ellipse_t Ellipse_t::operator+ ( const Point_t add  )  const [inline]

Adds the x and y values of the specified point to the center of the ellipse and returns the result in a new ellipse.

Definition at line 1833 of file UTGeometry.h.

Ellipse_t Ellipse_t::operator- ( const Point_t subtract  )  const [inline]

Subtracts the x and y value of the specified point from the center of the ellipse and returns the result in a new ellipse.

Definition at line 1840 of file UTGeometry.h.

const Ellipse_t & Ellipse_t::operator+= ( const Point_t add  )  [inline]

Adds the x and y values of the specified point to the center of the ellipse.

Definition at line 1847 of file UTGeometry.h.

const Ellipse_t & Ellipse_t::operator-= ( const Point_t subtract  )  [inline]

Subtracts the x and y value of the specified point from the center of the ellipse.

Definition at line 1855 of file UTGeometry.h.

bool Ellipse_t::Contains ( const Point_t point  )  const

Returns true if this ellipse contains the specified point.

bool Ellipse_t::Overlapping ( const Rect_t rect  )  const

Returns true if this ellipse (not its bounding box) at least partially overlaps the rectangle.

Rect_t Ellipse_t::BoundingBox (  )  const [inline]

Returns the bounding box which would enclose the entire ellipse.

Definition at line 1863 of file UTGeometry.h.

void Ellipse_t::GetBoundingBox ( out Rect_t bounding_box,
out double *  t_left = NULL,
out double *  t_top = NULL,
out double *  t_right = NULL,
out double *  t_bottom = NULL 
) const

Returns the bounding box which would enclose the entire ellipse. If any of the t_ pointers are not NULL, also returns the parametric value t at the corresponding apex.

void Ellipse_t::GetPointAndSlopeAtT ( double  t,
out Point_t point_on_ellipse,
out double *  slope = NULL 
) const

Calculates the point and/or slope on the ellipse at the specified parametric value t.

int Ellipse_t::FindXIntercepts ( float  y,
out float *  x,
out double *  t = NULL,
out double *  slope = NULL 
) const

Finds the X intercepts of the ellipse at the specified Y value. Returns the number of intercepts. The maximum number of inercepts is 2, so x, t, and slope must each, if they are not NULL, point to an array of two floats or doubles. Also returns the parametric value t and the slope at the points. Any of the output pointers can be NULL if the value is not needed.

int Ellipse_t::FindYIntercepts ( float  x,
out float *  y,
out double *  t = NULL,
out double *  slope = NULL 
) const

Finds the Y intercepts of the ellipse at the specified X value. Returns the number of intercepts. The maximum number of inercepts is 2, so x, t, and slope must each, if they are not NULL, point to an array of two floats or doubles. Also returns the parametric value t and the slope at the points. Any of the output pointers can be NULL if the value is not needed.

void Ellipse_t::FindClosestPoint ( const Point_t from,
bool  on_edge_if_inside,
out Point_t closest_point_on_ellipse,
out double *  t = NULL,
out double *  slope = NULL 
) const

Finds the closest point on the ellipse, returning the closest point through the closest_point_on_ellipse parameter, the corresponding parametric value through t, and the slope at that point through slope. Any of the output pointers can be NULL if the value is not needed. The on_edge_if_inside parameter can be false, in which case if from is inside the ellipse, it is returned as the closest point. If that is the case, t and slope, if needed, are set as if the point had been on the edge of the ellipse along the line from the center to from. This function is considerably slower than the other ellipse functions (1 ms average execution at 2 GHz) so it should be used with care.

void Ellipse_t::Rotate ( double  radians  ) 

Rotates the ellipse by the specified number of radians.

void Ellipse_t::RotateAbout ( double  radians,
const Point_t point 
)

Rotates the ellipse clockwise about the specified point by the specified number of radians.


The documentation for this class was generated from the following file:

Generated on Tue Dec 14 22:35:06 2010 for UT library by  doxygen 1.6.1