Namespaces

Types in MathNet.Spatial.Euclidean

Type Polygon2D

Namespace MathNet.Spatial.Euclidean

Interfaces IEquatable<Polygon2D>, IXmlSerializable

Class to represent a closed polygon.

Constructors

Static Functions

Methods

Properties

Public Constructors

Polygon2D(IEnumerable<Point2D> vertices)

Initializes a new instance of the Polygon2D class. At least three points are needed to construct a polygon. If less are passed an ArgumentException is thrown.
Parameters
IEnumerable<Point2D> vertices

A list of vertices.

Polygon2D(Point2D[] vertices)

Initializes a new instance of the Polygon2D class. At least three points are needed to construct a polygon. If less are passed an ArgumentException is thrown.
Parameters
Point2D[] vertices

A list of vertices.

Public Static Functions

bool ArePolygonVerticesColliding(Polygon2D a, Polygon2D b)

Compute whether or not two polygons are colliding based on whether or not the vertices of either are enclosed within the shape of the other. This is a simple means of detecting collisions that can fail if the two polygons are heavily overlapped in such a way that one protrudes through the other and out its opposing side without any vertices being enclosed.
Parameters
Polygon2D a

The first polygon.

Polygon2D b

The second polygon

Return
bool

True if the vertices collide; otherwise false.

Polygon2D GetConvexHullFromPoints(IEnumerable<Point2D> pointList, bool clockWise)

Using algorithm from Ouellet - https://www.codeproject.com/Articles/1210225/Fast-and-improved-D-Convex-Hull-algorithm-and-its, take an IEnumerable of Point2Ds and computes the two dimensional convex hull, returning it as a Polygon2D object.
Parameters
IEnumerable<Point2D> pointList

A list of points

bool clockWise

In which direction to return the points on the convex hull. If true, clockwise. Otherwise counter clockwise

Return
Polygon2D

A polygon.

Public Methods

bool EnclosesPoint(Point2D p)

Test whether a point is enclosed within a polygon. Points on the polygon edges are not counted as contained within the polygon.
Parameters
Point2D p

A point.

Return
bool

True if the point is inside the polygon; otherwise false.

bool Equals(Polygon2D other, double tolerance)

Returns a value to indicate if a pair of polygons are equal
Parameters
Polygon2D other

The polygon to compare against.

double tolerance

A tolerance (epsilon) to adjust for floating point error

Return
bool

true if the polygons are equal; otherwise false

bool Equals(Polygon2D other)

bool Equals(object obj)

int GetHashCode()

Type GetType()

Polygon2D ReduceComplexity(double singleStepTolerance)

Creates a new polygon from the existing polygon by removing any edges whose adjacent segments are considered colinear within the provided tolerance
Parameters
double singleStepTolerance

The tolerance by which adjacent edges should be considered collinear.

Return
Polygon2D

A polygon

Polygon2D Rotate(Angle angle)

Returns a polygon rotated around the origin
Parameters
Angle angle

The angle by which to rotate.

Return
Polygon2D

A new polygon that has been rotated.

Polygon2D RotateAround(Angle angle, Point2D center)

Rotate the polygon around the specified point
Parameters
Angle angle

The angle by which to rotate

Point2D center

A point at which to rotate around

Return
Polygon2D

A new polygon that has been rotated.

PolyLine2D ToPolyLine2D()

Converts the polygon into a PolyLine2D
Return
PolyLine2D

A polyline

string ToString()

Polygon2D TranslateBy(Vector2D vector)

Returns a new polygon which is translated (moved) by a vector
Parameters
Vector2D vector

A vector.

Return
Polygon2D

A new polygon that has been translated.

Public Properties

IEnumerable<LineSegment2D> Edges get;

Gets a list of Edges

int VertexCount get;

Gets the number of vertices in the polygon.

IEnumerable<Point2D> Vertices get;

Gets a list of vertices