This class implements convex polygons. More...
#include "Polygon.hpp"
Public Types | |
enum | SideT { Empty =0, On =1, Front =2, FrontAndOn =3, Back =4, BackAndOn =5, Both =6, BothAndOn =7, InIdentical =8, InMirrored =9 } |
Describes on which side of a plane the polygon is. More... | |
Public Member Functions | |
bool | IsValid (const double RoundEpsilon, const double MinVertexDist) const |
This methods returns whether a polygon is valid wrt. More... | |
Plane3T< T > | GetEdgePlane (unsigned long VertexNr, const T Epsilon) const |
Returns the plane that contains the polygon edge defined by (VertexNr, VertexNr+1), that is orthogonal to the polygons plane and whose normal vector points towards the polygon center. More... | |
Polygon3T< T > | GetMirror () const |
Returns a mirrored copy of this polygon, with reversed plane and reversed order. More... | |
T | GetArea () const |
Determines the spatial area (Flächeninhalt) of this polygon. More... | |
bool | HasVertex (const Vector3T< T > &A, const T Epsilon) const |
Determines whether this polygon has a vertex A, within Epsilon tolerance of the existing vertices. More... | |
SideT | WhatSide (const Plane3T< T > &P, const T HalfPlaneThickness) const |
Determines on what side of plane P this polygon is. More... | |
SideT | WhatSideSimple (const Plane3T< T > &P, const T HalfPlaneThickness) const |
Like WhatSide(), but it integrates the "...AndOn" answers with the non-"AndOn" answers. More... | |
bool | Overlaps (const Polygon3T< T > &OtherPoly, bool ReportTouchesAsOverlaps, const T EdgeThickness) const |
Determines whether this polygon overlaps OtherPoly (in the same plane). More... | |
bool | Encloses (const Polygon3T< T > &OtherPoly, bool MayTouchEdges, const T EdgeThickness) const |
Determines whether this polygon entirely encloses OtherPoly (in the same or mirrored plane). More... | |
ArrayT< Polygon3T< T > > | GetSplits (const Plane3T< T > &SplitPlane, const T HalfPlaneThickness) const |
Splits the polygon along the passed plane. More... | |
void | GetChoppedUpAlong (const Polygon3T< T > &Poly, const T EdgeThickness, ArrayT< Polygon3T< T > > &NewPolys) const |
Cuts this polygon along the edges of Poly. More... | |
void | FillTJunctions (const Polygon3T< T > &Poly, const T EdgeThickness) |
If poly builds t-junctions at this polygon, the according vertives are added to this polygon. More... | |
Static Public Member Functions | |
static Polygon3T< T > | Merge (const Polygon3T< T > &Poly1, const Polygon3T< T > &Poly2, const T EdgeThickness) |
Merge Poly1 and Poly2 under the following prerequisites: More... | |
static void | Complete (ArrayT< Polygon3T< T > > &Polys, const T HalfPlaneThickness, const Vector3T< T > &BoundingSphereCenter=Vector3T< T >(0, 0, 0), const T BoundingSphereRadius=10.0 *1000.0 *1000.0) |
Given a brush (here: array of polygons), from which only the planes are known. More... | |
Public Attributes | |
ArrayT< Vector3T< T > > | Vertices |
Vertices of this polygon. More... | |
Plane3T< T > | Plane |
Plane of this polygon. More... | |
This class implements convex polygons.
Properties / invariants of polygons:
enum Polygon3T::SideT |
Describes on which side of a plane the polygon is.
Enumerator | |
---|---|
Empty |
The polygon is empty (it has no vertices). |
On |
The polygon has vertices in the plane. Note that this value alone is never returned by WhatSide(). |
Front |
The polygon has vertices on the front-side of the plane. |
FrontAndOn |
The polygon has vertices on the front-side of and in the plane. |
Back |
The polygon has vertices on the back-side of the plane. |
BackAndOn |
The polygon has vertices on the back-side of and in the plane. |
Both |
The polygon has vertices on both sides of the plane. |
BothAndOn |
The polygon has vertices on both sides of and in the plane. |
InIdentical |
The polygon is in the plane. |
InMirrored |
The polygon is in the mirrored version of the plane (opposite normal vectors). |
|
static |
Given a brush (here: array of polygons), from which only the planes are known.
WARNING: All normal vectors of the polygons must point to the outside! Find the vertices of all polygons and sort them in clockwise direction. WARNING: Degenerated inputs are also possible, e.g. the planes from a cube with one side missing. Those cases can't be caught here as errors because this functionality is necessary for portal creation. In this case polygons with fewer than 3 vertices are returned and an explicit validity check is necessary! It is also possible that the input planes of a polygon for example specify a triangle where one edge is shorter than GeometryEpsilon. In this case the vertices would be combined and a polygon with only 2 vertices would be the result! Further example for similar degenerated cases are also possible. Consequence: Check the returned polygon sets ALWAYS for validity, e.g. Polys[...].Vertices.Size()>=3 !
Polys | Polygons to complete |
HalfPlaneThickness | DOCTODO |
BoundingSphereCenter | DOCTODO |
BoundingSphereRadius | DOCTODO |
bool Polygon3T< T >::Encloses | ( | const Polygon3T< T > & | OtherPoly, |
bool | MayTouchEdges, | ||
const T | EdgeThickness | ||
) | const |
Determines whether this polygon entirely encloses OtherPoly (in the same or mirrored plane).
OtherPoly | The polygon for which is determined whether it is enclosed by this polygon. |
MayTouchEdges | If true, OtherPoly may touch the edges of this polygon within EdgeThickness tolerance and is still being considered enclosed. If false, OtherPoly must truly be inside this polygon, and it must not touch its edges. |
EdgeThickness | describes both the "thickness" of the edges of this polygon and the minimum length of the edges of this polygon and OtherPoly. |
InvalidOperationE | if an edge of this polygon is shorter than EdgeThickness. |
void Polygon3T< T >::FillTJunctions | ( | const Polygon3T< T > & | Poly, |
const T | EdgeThickness | ||
) |
If poly builds t-junctions at this polygon, the according vertives are added to this polygon.
WARNING: The resulting polygon will, in general, be INVALID (several vertices per edge).
Poly | Polygon that is checked for t-junctions with this polygon. |
EdgeThickness | DOCTODO |
T Polygon3T< T >::GetArea | ( | ) | const |
Determines the spatial area (Flächeninhalt) of this polygon.
void Polygon3T< T >::GetChoppedUpAlong | ( | const Polygon3T< T > & | Poly, |
const T | EdgeThickness, | ||
ArrayT< Polygon3T< T > > & | NewPolys | ||
) | const |
Cuts this polygon along the edges of Poly.
Prerequisite: this->Overlaps(Poly)! The last polygon in NewPolys is the overlapping one (*), the front entries lie outside the polygon. (If this polygon is contained in Poly (even then this->Overlaps(Poly) is true), NewPolys contains only a copy of this polygon.) This also works without this prerequisite, but (*) is no longer true! WARNING: This function uses GetSplits() and therfore has the same troubles as this method!
Poly | Polygon to cut this polygon with. |
EdgeThickness | DOCTODO |
NewPolys | The resulting polygons. |
|
inline |
Returns the plane that contains the polygon edge defined by (VertexNr, VertexNr+1), that is orthogonal to the polygons plane and whose normal vector points towards the polygon center.
VertexNr | The edge defined by (VertexNr, VertexNr+1) for which a plane should be created. |
Epsilon | Maximum error value. |
DivisionByZeroE | if the edge is shorter than accounted for by Epsilon. |
Returns a mirrored copy of this polygon, with reversed plane and reversed order.
(If this polygon was valid, the mirrored polygon is valid, too.)
ArrayT< Polygon3T< T > > Polygon3T< T >::GetSplits | ( | const Plane3T< T > & | SplitPlane, |
const T | HalfPlaneThickness | ||
) | const |
Splits the polygon along the passed plane.
WARNING: This function can return invalid polygons from a valid polygon! This happens for example if the polygon is a sharp wedge whose top is cut of. If the wedge was sharp enough, vertices may be created at the cut surface that concur with each other! Therefore the resulting polygons should ALWAYS be checked for validity by IsValid()!
SplitPlane | The plane to split the polygon with. |
HalfPlaneThickness | DOCTODO |
Determines whether this polygon has a vertex A, within Epsilon tolerance of the existing vertices.
bool Polygon3T< T >::IsValid | ( | const double | RoundEpsilon, |
const double | MinVertexDist | ||
) | const |
This methods returns whether a polygon is valid wrt.
the above stipulated properties/terms.
RoundEpsilon | The epsilon tolerance that is acceptable for rounding errors. |
MinVertexDist | The minimum distance that vertices must be apart. The MinVertexDist value should be a good deal larger than the RoundEpsilon value, because very subtle problems can easily arise whenever the "structural object size" is as small as the maximally permitted rounding error! |
|
static |
Merge Poly1 and Poly2 under the following prerequisites:
Poly1 | First polygon to merge. |
Poly2 | Second polygon to merge. |
EdgeThickness | DOCTODO |
InvalidOperationE | if Poly1 and Poly2 could not be merged. |
bool Polygon3T< T >::Overlaps | ( | const Polygon3T< T > & | OtherPoly, |
bool | ReportTouchesAsOverlaps, | ||
const T | EdgeThickness | ||
) | const |
Determines whether this polygon overlaps OtherPoly (in the same plane).
OtherPoly | The polygon for which is determined whether it is overlapped by this polygon. |
ReportTouchesAsOverlaps | If true, an overlap is reported even if it has zero area, that is, even if the two polygons merely "touch" within the thickness of the edges. If false, an overlap is only reported if it has a positive, non-zero area. |
EdgeThickness | describes both the "thickness" of the edges within which small gaps (i.e. non-overlaps) are tolerated, and the minimum length of the edges of this polygon and OtherPoly. |
InvalidOperationE | if an edge of this polygon or OtherPoly is shorter than EdgeThickness. |
Polygon3T< T >::SideT Polygon3T< T >::WhatSide | ( | const Plane3T< T > & | P, |
const T | HalfPlaneThickness | ||
) | const |
Determines on what side of plane P this polygon is.
P | The plane to check with. |
HalfPlaneThickness | DOCTODO |
Polygon3T< T >::SideT Polygon3T< T >::WhatSideSimple | ( | const Plane3T< T > & | P, |
const T | HalfPlaneThickness | ||
) | const |
Like WhatSide(), but it integrates the "...AndOn" answers with the non-"AndOn" answers.
That is, instead of FrontAndOn only Front is returned, instead of BackAndOn Back, and instead of BothAndOn Both is returned.
P | The plane to check with. |
HalfPlaneThickness | DOCTODO |