Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

C2DPolygon Class Reference

Class which represents a polygon. More...

#include <2DPolygon.h>

Inheritance diagram for C2DPolygon:

C2DPolyBase C2DBase List of all members.

Public Member Functions

 C2DPolygon (void)
 Constructor.
 C2DPolygon (const C2DPoint *pPoint, unsigned int nNumber, bool bReorderIfNeeded=false)
 Constructor.
 C2DPolygon (const C2DPointSet &Points, bool bReorderIfNeeded=false)
 Constructor.
 C2DPolygon (const C2DPolygon &Other)
 Constructor.
 C2DPolygon (const C2DPolyBase &Other)
 Constructor.
 ~C2DPolygon (void)
 Destructor.
bool Create (const C2DRoute &Route)
 Sets the point list to that of the route provided. Route can be closed or not.
bool Create (const C2DPoint *pPoint, unsigned int nNumber, bool bReorderIfNeeded=false)
 Creates the polygon with optional reordering of points.
bool Create (const C2DPointSet &Points, bool bReorderIfNeeded=false)
 Creates the polygon with optional reordering of points.
bool CreateRegular (const C2DPoint &Centre, double dDistanceToPoints, int nNumberSides)
 Creates a regular polygon.
bool CreateConvexHull (const C2DPolygon &Other)
 Creates a convex hull from another polygon. Uses Graham's algorithm.
bool CreateRandom (const C2DRect &cBoundary, int nMinPoints, int nMaxPoints)
 Creates a randon polygon.
bool CreateMorph (const C2DPolygon &OtherFrom, const C2DPolygon &OtherTo, double dFactor)
 Mophs this polygon into another by the factor given.
bool CreateConvexSubAreas (void)
 Creates convex sub areas by joining inflection if possible or joining inflected points with other points that will remove the inflection.
void ClearConvexSubAreas (void)
 Removes the convex sub areas.
bool Contains (const C2DPoint &pt) const
 True if the point is contained.
bool Contains (const C2DPolygon &Other) const
 True if the polygon is contained.
bool Contains (const C2DHoledPolyBase &Other) const
 True if it entirely contains the other.
bool Contains (const C2DLine &Line) const
 True if the Line is contained.
bool Contains (const C2DLineBase &Line) const
 True if the Line is contained.
bool Crosses (const C2DLineBase &Line) const
 True if the lines of this cross the line.
bool Crosses (const C2DLineBase &Line, C2DPointSet *IntersectionPts) const
 True if a given lines crosses any line in the polygon. Records the intersection points in order.
bool CrossesRay (const C2DLine &Ray, C2DPointSet *IntersectionPts) const
 True if the ray crosses the polygon, records the points in order.
bool IsConvex (void)
 True if the polygon is convex.
void Clear (void)
 Clears all.
void RotateToRight (double dAng, const C2DPoint &Origin)
 Rotates the polygon to the right around the origin given.
void RotateToRight (double dAng)
 Rotates the polygon to the right around the centroid.
void Move (const C2DVector &Vector)
 Moves the polygon.
void Grow (double dFactor)
 Grows the polygon from the centre.
void Grow (double dFactor, const C2DPoint &Origin)
 Grows from the origin given.
void Reflect (const C2DPoint &Point)
 Reflects throught the point provided.
void Reflect (const C2DLine &Line)
 Reflects throught the line provided.
const C2DPolygonoperator= (const C2DPolygon &Other)
 Assignment.
bool HasRepeatedPoints (void) const
 True if there are repeated points.
bool IsClockwise (void)
 True if clockwise.
void Project (const C2DVector &Vector, CInterval &Interval) const
 Projects the polygon onto a vector providing the interval of projection on the vector.
void Project (const C2DLine &Line, CInterval &Interval) const
 Projects the polygon onto a line providing the interval of projection on the vector.
const C2DPolygonGetSubArea (int nIndex) const
 Returns a pointer to the sub area.
void GetConvexSubAreas (C2DPolygonSet &SubAreas) const
 Returns the convex sub areas if created.
bool Overlaps (const C2DPolygon &Other, C2DVector &MinimumTranslationVector) const
 Returns true if there is an overlap between this and the other polygon and the vector required to move them apart from one another. Exact for a convex polygon. For non-convex, the function effectively works on the convex hull. However, a non-convex polygon can be split into convex polygons and then the calculated translation vector is more accurate.
bool Overlaps (const C2DPolygon &Other) const
 True if this overlap the other.
void Avoid (const C2DPolygon &Other)
 Calls the Overlaps function and moves this away from the other.
unsigned int GetPointsCount (void) const
 Returns the number of points.
const C2DPoint GetCentroid (void) const
 Returns the centroid.
double GetArea () const
 Returns the area.
double GetAreaSigned () const
 Returns the area signed (-ve if clockwise).
const C2DPointGetPoint (unsigned short nPointIndex) const
 Returns a pointer to the point required;.
void GetPointsCopy (C2DPointSet &PointCopy) const
 Copies the points into the set object provided.
const C2DLineGetLine (unsigned int i) const
 Returns a constant pointer to the line.
int GetLeftMostPoint (void) const
 Returns the left most point.
void Smooth (double dMinAngle=conPI *0.8, double dCropFactor=0.8)
 Smooths the polygon.
void GetBoundingCircle (C2DCircle &Circle) const
 Get the minimum bounding circle.
void GetNonOverlaps (const C2DPolygon &Other, C2DHoledPolygonSet &HoledPolygons, CGrid::eDegenerateHandling eDegen=CGrid::None) const
 Returns the difference between this and the other.
void GetNonOverlaps (const C2DPolygon &Other, C2DHoledPolyBaseSet &HoledPolygons, CGrid::eDegenerateHandling eDegen=CGrid::None) const
 Returns the difference between this and the other. Access to base class.
void GetUnion (const C2DPolygon &Other, C2DHoledPolygonSet &HoledPolygons, CGrid::eDegenerateHandling eDegen=CGrid::None) const
 Returns the union of tihis and the other.
void GetUnion (const C2DPolygon &Other, C2DHoledPolyBaseSet &HoledPolygons, CGrid::eDegenerateHandling eDegen=CGrid::None) const
 Returns the union of tihis and the other. Access to base class.
void GetOverlaps (const C2DPolygon &Other, C2DHoledPolygonSet &Polygons, CGrid::eDegenerateHandling eDegen=CGrid::None) const
 Returns the overlap between this and the other.
void GetOverlaps (const C2DPolygon &Other, C2DHoledPolyBaseSet &Polygons, CGrid::eDegenerateHandling eDegen=CGrid::None) const
 Returns the overlap between this and the other. Access to base class.

Static Public Member Functions

static void GetMinProjection (C2DPolygonSet &Polygons, C2DVector &Result, CInterval &Interval)
 Returns the vector on which the projection of the whole set of polygons is minimal. Also returns the projection interval on that vector.

Detailed Description

Class which represents a polygon.

Class which represents a polygon which is defined as a sequence of straight lines that are joined and closed, with no holes and no self intersections.

User adds points and then calls the create function. Can opt to add points without any order and in which case the points are reordered so that the perimeter of the shape is minimised and there are no crossing lines.

Supports a variety of functions including functions to find the intersection, union and non-intersection of two polygons.

---------------------------------------------------------------------------


Constructor & Destructor Documentation

C2DPolygon::C2DPolygon void   ) 
 

Constructor.

--------------------------------------------------------------------------
C2DPolygon::C2DPolygon

---------------------------------------------------------------------------

C2DPolygon::C2DPolygon const C2DPoint pPoint,
unsigned int  nNumber,
bool  bReorderIfNeeded = false
 

Constructor.

--------------------------------------------------------------------------
C2DPolygon::C2DPolygon

---------------------------------------------------------------------------

C2DPolygon::C2DPolygon const C2DPointSet Points,
bool  bReorderIfNeeded = false
 

Constructor.

--------------------------------------------------------------------------
C2DPolygon::C2DPolygon

---------------------------------------------------------------------------

C2DPolygon::C2DPolygon const C2DPolygon Other  ) 
 

Constructor.

--------------------------------------------------------------------------
C2DPolygon::C2DPolygon

---------------------------------------------------------------------------

C2DPolygon::C2DPolygon const C2DPolyBase Other  ) 
 

Constructor.

--------------------------------------------------------------------------
C2DPolygon::C2DPolygon

---------------------------------------------------------------------------

C2DPolygon::~C2DPolygon void   ) 
 

Destructor.

--------------------------------------------------------------------------
C2DPolygon::~C2DPolygon

---------------------------------------------------------------------------


Member Function Documentation

void C2DPolygon::Avoid const C2DPolygon Other  ) 
 

Calls the Overlaps function and moves this away from the other.

--------------------------------------------------------------------------
C2DPolygon::Avoid

---------------------------------------------------------------------------

void C2DPolygon::Clear void   ) 
 

Clears all.

--------------------------------------------------------------------------
C2DPolygon::Clear

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

void C2DPolygon::ClearConvexSubAreas void   ) 
 

Removes the convex sub areas.

--------------------------------------------------------------------------
C2DPolygon::ClearConvexSubAreas

---------------------------------------------------------------------------

bool C2DPolygon::Contains const C2DLineBase Line  )  const
 

True if the Line is contained.

--------------------------------------------------------------------------
C2DPolygon::Contains

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

bool C2DPolygon::Contains const C2DLine Line  )  const
 

True if the Line is contained.

--------------------------------------------------------------------------
C2DPolygon::Contains

---------------------------------------------------------------------------

bool C2DPolygon::Contains const C2DHoledPolyBase Other  )  const [inline]
 

True if it entirely contains the other.

--------------------------------------------------------------------------
C2DPolyBase::Contains

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

bool C2DPolygon::Contains const C2DPolygon Other  )  const
 

True if the polygon is contained.

--------------------------------------------------------------------------
C2DPolygon::Contains

---------------------------------------------------------------------------

bool C2DPolygon::Contains const C2DPoint pt  )  const
 

True if the point is contained.

--------------------------------------------------------------------------
C2DPolygon::Contains

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

bool C2DPolygon::Create const C2DPointSet Points,
bool  bReorderIfNeeded = false
 

Creates the polygon with optional reordering of points.

--------------------------------------------------------------------------
C2DPolygon::Create

---------------------------------------------------------------------------

bool C2DPolygon::Create const C2DPoint pPoint,
unsigned int  nNumber,
bool  bReorderIfNeeded = false
 

Creates the polygon with optional reordering of points.

--------------------------------------------------------------------------
C2DPolygon::Create

---------------------------------------------------------------------------

bool C2DPolygon::Create const C2DRoute Route  ) 
 

Sets the point list to that of the route provided. Route can be closed or not.

--------------------------------------------------------------------------
C2DPolygon::Create

---------------------------------------------------------------------------

bool C2DPolygon::CreateConvexHull const C2DPolygon Other  ) 
 

Creates a convex hull from another polygon. Uses Graham's algorithm.

--------------------------------------------------------------------------
C2DPolygon::CreateConvexHull

---------------------------------------------------------------------------

bool C2DPolygon::CreateConvexSubAreas void   ) 
 

Creates convex sub areas by joining inflection if possible or joining inflected points with other points that will remove the inflection.

Creates convex sub areas of the current polygon. These can then be extracted. This function is also useful when obtaining minimum translation vectors.

See also:
Overlaps function.

bool C2DPolygon::CreateMorph const C2DPolygon OtherFrom,
const C2DPolygon OtherTo,
double  dFactor
 

Mophs this polygon into another by the factor given.

--------------------------------------------------------------------------
C2DPolygon::CreateMorph

---------------------------------------------------------------------------

bool C2DPolygon::CreateRandom const C2DRect cBoundary,
int  nMinPoints,
int  nMaxPoints
 

Creates a randon polygon.

--------------------------------------------------------------------------
C2DPolygon::CreateRandom

---------------------------------------------------------------------------

bool C2DPolygon::CreateRegular const C2DPoint Centre,
double  dDistanceToPoints,
int  nNumberSides
 

Creates a regular polygon.

--------------------------------------------------------------------------
C2DPolygon::CreateRegular

---------------------------------------------------------------------------

bool C2DPolygon::Crosses const C2DLineBase Line,
C2DPointSet IntersectionPts
const
 

True if a given lines crosses any line in the polygon. Records the intersection points in order.

True if the lines of this cross the line. Returns the points in order of their position on the line.

Reimplemented from C2DPolyBase.

bool C2DPolygon::Crosses const C2DLineBase Line  )  const
 

True if the lines of this cross the line.

--------------------------------------------------------------------------
C2DPolygon::Crosses

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

bool C2DPolygon::CrossesRay const C2DLine Ray,
C2DPointSet IntersectionPts
const
 

True if the ray crosses the polygon, records the points in order.

True if the lines of this cross the ray. Returns the points in order of their position on the ray. (assumes the line is infinite).

Reimplemented from C2DPolyBase.

double C2DPolygon::GetArea  )  const
 

Returns the area.

--------------------------------------------------------------------------
C2DPolygon::GetArea

---------------------------------------------------------------------------

double C2DPolygon::GetAreaSigned  )  const
 

Returns the area signed (-ve if clockwise).

--------------------------------------------------------------------------
C2DPolygon::GetArea

---------------------------------------------------------------------------

void C2DPolygon::GetBoundingCircle C2DCircle Circle  )  const
 

Get the minimum bounding circle.

--------------------------------------------------------------------------
C2DPolygon::GetBoundingCircle

---------------------------------------------------------------------------

const C2DPoint C2DPolygon::GetCentroid void   )  const
 

Returns the centroid.

--------------------------------------------------------------------------
C2DPolygon::GetCentroid

---------------------------------------------------------------------------

void C2DPolygon::GetConvexSubAreas C2DPolygonSet SubAreas  )  const
 

Returns the convex sub areas if created.

--------------------------------------------------------------------------
C2DPolygon::GetConvexSubAreas

---------------------------------------------------------------------------

int C2DPolygon::GetLeftMostPoint void   )  const
 

Returns the left most point.

--------------------------------------------------------------------------
C2DPolygon::GetLeftMostPoint

---------------------------------------------------------------------------

void C2DPolygon::GetMinProjection C2DPolygonSet Polygons,
C2DVector Result,
CInterval Interval
[static]
 

Returns the vector on which the projection of the whole set of polygons is minimal. Also returns the projection interval on that vector.

Returns the vector which results in the smallest projection of all the polygons in the array and the interval representing that translation.

void C2DPolygon::GetNonOverlaps const C2DPolygon Other,
C2DHoledPolyBaseSet HoledPolygons,
CGrid::eDegenerateHandling  eDegen = CGrid::None
const
 

Returns the difference between this and the other. Access to base class.

--------------------------------------------------------------------------
C2DPolygon::GetNonOverlaps

---------------------------------------------------------------------------

void C2DPolygon::GetNonOverlaps const C2DPolygon Other,
C2DHoledPolygonSet HoledPolygons,
CGrid::eDegenerateHandling  eDegen = CGrid::None
const
 

Returns the difference between this and the other.

--------------------------------------------------------------------------
C2DPolygon::GetNonOverlaps

---------------------------------------------------------------------------

void C2DPolygon::GetOverlaps const C2DPolygon Other,
C2DHoledPolyBaseSet Polygons,
CGrid::eDegenerateHandling  eDegen = CGrid::None
const
 

Returns the overlap between this and the other. Access to base class.

--------------------------------------------------------------------------
C2DPolygon::GetOverlaps

---------------------------------------------------------------------------

void C2DPolygon::GetOverlaps const C2DPolygon Other,
C2DHoledPolygonSet Polygons,
CGrid::eDegenerateHandling  eDegen = CGrid::None
const
 

Returns the overlap between this and the other.

--------------------------------------------------------------------------
C2DPolygon::GetOverlaps

---------------------------------------------------------------------------

const C2DPoint * C2DPolygon::GetPoint unsigned short  nPointIndex  )  const
 

Returns a pointer to the point required;.

--------------------------------------------------------------------------
C2DPolygon::GetPoint

---------------------------------------------------------------------------

void C2DPolygon::GetPointsCopy C2DPointSet PointCopy  )  const
 

Copies the points into the set object provided.

--------------------------------------------------------------------------
C2DPolygon::GetPointsCopy

---------------------------------------------------------------------------

const C2DPolygon * C2DPolygon::GetSubArea int  nIndex  )  const
 

Returns a pointer to the sub area.

--------------------------------------------------------------------------
C2DPolygon::GetSubArea

---------------------------------------------------------------------------

void C2DPolygon::GetUnion const C2DPolygon Other,
C2DHoledPolyBaseSet HoledPolygons,
CGrid::eDegenerateHandling  eDegen = CGrid::None
const
 

Returns the union of tihis and the other. Access to base class.

--------------------------------------------------------------------------
C2DPolygon::GetUnion

---------------------------------------------------------------------------

void C2DPolygon::GetUnion const C2DPolygon Other,
C2DHoledPolygonSet HoledPolygons,
CGrid::eDegenerateHandling  eDegen = CGrid::None
const
 

Returns the union of tihis and the other.

--------------------------------------------------------------------------
C2DPolygon::GetUnion

---------------------------------------------------------------------------

void C2DPolygon::Grow double  dFactor,
const C2DPoint Origin
[virtual]
 

Grows from the origin given.

--------------------------------------------------------------------------
C2DPolygon::Grow

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

void C2DPolygon::Grow double  dFactor  ) 
 

Grows the polygon from the centre.

--------------------------------------------------------------------------
C2DPolygon::Grow

---------------------------------------------------------------------------

bool C2DPolygon::HasRepeatedPoints void   )  const
 

True if there are repeated points.

--------------------------------------------------------------------------
C2DPolygon::HasRepeatedPoints

---------------------------------------------------------------------------

bool C2DPolygon::IsClockwise void   ) 
 

True if clockwise.

--------------------------------------------------------------------------
C2DPolygon::IsClockwise

---------------------------------------------------------------------------

bool C2DPolygon::IsConvex void   ) 
 

True if the polygon is convex.

--------------------------------------------------------------------------
C2DPolygon::IsConvex

---------------------------------------------------------------------------

void C2DPolygon::Move const C2DVector Vector  )  [virtual]
 

Moves the polygon.

--------------------------------------------------------------------------
C2DPolygon::Move

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

const C2DPolygon & C2DPolygon::operator= const C2DPolygon Other  ) 
 

Assignment.

--------------------------------------------------------------------------
C2DPolygon::operator =

---------------------------------------------------------------------------

bool C2DPolygon::Overlaps const C2DPolygon Other  )  const
 

True if this overlap the other.

--------------------------------------------------------------------------
C2DPolygon::Overlaps

---------------------------------------------------------------------------

bool C2DPolygon::Overlaps const C2DPolygon Other,
C2DVector MinimumTranslationVector
const
 

Returns true if there is an overlap between this and the other polygon and the vector required to move them apart from one another. Exact for a convex polygon. For non-convex, the function effectively works on the convex hull. However, a non-convex polygon can be split into convex polygons and then the calculated translation vector is more accurate.

True if this overlaps another and returns the translation vector required to move this apart. Exact if this is convex, approximate if concave. Better approximation if convex sub areas have been created.

void C2DPolygon::Project const C2DLine Line,
CInterval Interval
const [virtual]
 

Projects the polygon onto a line providing the interval of projection on the vector.

--------------------------------------------------------------------------
C2DPolygon::Project

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

void C2DPolygon::Project const C2DVector Vector,
CInterval Interval
const [virtual]
 

Projects the polygon onto a vector providing the interval of projection on the vector.

--------------------------------------------------------------------------
C2DPolygon::Project

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

void C2DPolygon::Reflect const C2DLine Line  )  [virtual]
 

Reflects throught the line provided.

--------------------------------------------------------------------------
C2DPolygon::Reflect

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

void C2DPolygon::Reflect const C2DPoint Point  )  [virtual]
 

Reflects throught the point provided.

--------------------------------------------------------------------------
C2DPolygon::Reflect

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

void C2DPolygon::RotateToRight double  dAng  ) 
 

Rotates the polygon to the right around the centroid.

--------------------------------------------------------------------------
C2DPolygon::RotateToRight

---------------------------------------------------------------------------

void C2DPolygon::RotateToRight double  dAng,
const C2DPoint Origin
[virtual]
 

Rotates the polygon to the right around the origin given.

--------------------------------------------------------------------------
C2DPolygon::RotateToRight

---------------------------------------------------------------------------

Reimplemented from C2DPolyBase.

void C2DPolygon::Smooth double  dMinAngle = conPI * 0.8,
double  dCropFactor = 0.8
 

Smooths the polygon.

--------------------------------------------------------------------------
C2DPolygon::Smooth

---------------------------------------------------------------------------


The documentation for this class was generated from the following files:
Generated on Mon Apr 21 11:43:52 2008 for GeoLib by  doxygen 1.4.4