Math.Geometry


Polygon2D Module

Functions and values

Function or value Description

area polygon

Full Usage: area polygon

Parameters:
Returns: Quantity<Squared<'Units>>

Get the area of a polygon. This value will never be negative.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: Quantity<Squared<'Units>>

boundingBox polygon

Full Usage: boundingBox polygon

Parameters:
Returns: BoundingBox2D<'Units, 'Coordinates> option

Get the minimal bounding box containing a given polygon. Returns `None` if the polygon has no vertices.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: BoundingBox2D<'Units, 'Coordinates> option

centroid polygon

Full Usage: centroid polygon

Parameters:
Returns: Point2D<'Units, 'Coordinates> option

Get the centroid of a polygon. Returns `Nothing` if the polygon has no vertices or zero area.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: Point2D<'Units, 'Coordinates> option

contains point polygon

Full Usage: contains point polygon

Parameters:
    point : Point2D<'Units, 'Coordinates>
    polygon : Polygon2D<'Units, 'Coordinates>

Returns: bool

Check if a polygon contains a given point. This is an O(n) operation. The polygon can have holes and does not need to be convex.

point : Point2D<'Units, 'Coordinates>
polygon : Polygon2D<'Units, 'Coordinates>
Returns: bool

convexHull points

Full Usage: convexHull points

Parameters:
    points : Point2D<'Units, 'Coordinates> list

Returns: Polygon2D<'Units, 'Coordinates>

Build the [convex hull](https://en.wikipedia.org/wiki/Convex_hull) of a list of points. This is an O(n log n) operation.

points : Point2D<'Units, 'Coordinates> list
Returns: Polygon2D<'Units, 'Coordinates>

edges polygon

Full Usage: edges polygon

Parameters:
Returns: LineSegment2D<'Units, 'Coordinates> list

Get all edges of a polygon. This will include both outer edges and inner (hole) edges.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: LineSegment2D<'Units, 'Coordinates> list

innerLoops polygon

Full Usage: innerLoops polygon

Parameters:
Returns: Point2D<'Units, 'Coordinates> list list

Get the holes (if any) of a polygon, each defined by a list of vertices. Each list of vertices will be in clockwise order.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: Point2D<'Units, 'Coordinates> list list

loopEdges vertices_

Full Usage: loopEdges vertices_

Parameters:
    vertices_ : Point2D<'Units, 'Coordinates> list

Returns: LineSegment2D<'Units, 'Coordinates> list
vertices_ : Point2D<'Units, 'Coordinates> list
Returns: LineSegment2D<'Units, 'Coordinates> list

mapVertices f invert polygon

Full Usage: mapVertices f invert polygon

Parameters:
    f : Point2D<'UnitA, 'CoordinatesA> -> Point2D<'UnitB, 'CoordinatesB>
    invert : bool
    polygon : Polygon2D<'UnitA, 'CoordinatesA>

Returns: Polygon2D<'UnitB, 'CoordinatesB>
f : Point2D<'UnitA, 'CoordinatesA> -> Point2D<'UnitB, 'CoordinatesB>
invert : bool
polygon : Polygon2D<'UnitA, 'CoordinatesA>
Returns: Polygon2D<'UnitB, 'CoordinatesB>

mirrorAcross axis polygon

Full Usage: mirrorAcross axis polygon

Parameters:
    axis : Axis2D<'Units, 'Coordinates>
    polygon : Polygon2D<'Units, 'Coordinates>

Returns: Polygon2D<'Units, 'Coordinates>

Mirror a polygon across the given axis. The order of the polygon's vertices will be reversed so that the resulting polygon still has its outer vertices in counterclockwise order and its inner vertices in clockwise order.

axis : Axis2D<'Units, 'Coordinates>
polygon : Polygon2D<'Units, 'Coordinates>
Returns: Polygon2D<'Units, 'Coordinates>

outerLoop polygon

Full Usage: outerLoop polygon

Parameters:
Returns: Point2D<'Units, 'Coordinates> list

Get the list of vertices defining the outer loop (border) of a polygon. The vertices will be in counterclockwise order.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: Point2D<'Units, 'Coordinates> list

perimeter polygon

Full Usage: perimeter polygon

Parameters:
Returns: Quantity<'Units>

Get the perimeter of a polygon (the sum of the lengths of its edges). This includes the outer perimeter and the perimeter of any holes.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: Quantity<'Units>

placeIn frame polygon

Full Usage: placeIn frame polygon

Parameters:
    frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
    polygon : Polygon2D<'Units, 'LocalCoordinates>

Returns: Polygon2D<'Units, 'GlobalCoordinates>

Take a polygon considered to be defined in local coordinates relative to a given reference frame, and return that polygon expressed in global coordinates. If the given frame is left-handed, the order of the polygon's vertices will be reversed so that the resulting polygon still has its outer vertices in counterclockwise order and its inner vertices in clockwise order.

frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
polygon : Polygon2D<'Units, 'LocalCoordinates>
Returns: Polygon2D<'Units, 'GlobalCoordinates>

relativeTo frame polygon

Full Usage: relativeTo frame polygon

Parameters:
    frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
    polygon : Polygon2D<'Units, 'GlobalCoordinates>

Returns: Polygon2D<'Units, 'LocalCoordinates>

Take a polygon defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame. If the given frame is left-handed, the order of the polygon's vertices will be reversed so that the resulting polygon still has its outer vertices in counterclockwise order and its inner vertices in clockwise order.

frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
polygon : Polygon2D<'Units, 'GlobalCoordinates>
Returns: Polygon2D<'Units, 'LocalCoordinates>

rotateAround point angle polygon

Full Usage: rotateAround point angle polygon

Parameters:
    point : Point2D<'Units, 'Coordinates>
    angle : Angle
    polygon : Polygon2D<'Units, 'Coordinates>

Returns: Polygon2D<'Units, 'Coordinates>

Rotate a polygon around the given center point counterclockwise by the given angle.

point : Point2D<'Units, 'Coordinates>
angle : Angle
polygon : Polygon2D<'Units, 'Coordinates>
Returns: Polygon2D<'Units, 'Coordinates>

scaleAbout point scale polygon

Full Usage: scaleAbout point scale polygon

Parameters:
    point : Point2D<'Units, 'Coordinates>
    scale : float
    polygon : Polygon2D<'Units, 'Coordinates>

Returns: Polygon2D<'Units, 'Coordinates>

Scale a polygon about a given center point by a given scale. If the given scale is negative, the order of the polygon's vertices will be reversed so that the resulting polygon still has its outer vertices in counterclockwise order and its inner vertices in clockwise order.

point : Point2D<'Units, 'Coordinates>
scale : float
polygon : Polygon2D<'Units, 'Coordinates>
Returns: Polygon2D<'Units, 'Coordinates>

singleLoop givenOuterLoop

Full Usage: singleLoop givenOuterLoop

Parameters:
    givenOuterLoop : Point2D<'a, 'b> list

Returns: Polygon2D<'a, 'b>

Construct a polygon without holes from a list of its vertices: let rectangle = Polygon2D.singleLoop [ Point2D.meters 1. 1. Point2D.meters 3. 1. Point2D.meters 3. 2. Point2D.meters 1. 2. ] The last vertex is implicitly considered to be connected back to the first vertex (you do not have to close the polygon explicitly). Vertices should ideally be provided in counterclockwise order; if they are provided in clockwise order they will be reversed.

givenOuterLoop : Point2D<'a, 'b> list
Returns: Polygon2D<'a, 'b>

translate amount polygon

Full Usage: translate amount polygon

Parameters:
Returns: Polygon2D<'Units, 'Coordinates>
amount : Vector2D<'Units, 'Coordinates>
polygon : Polygon2D<'Units, 'Coordinates>
Returns: Polygon2D<'Units, 'Coordinates>

translateBy vector polygon

Full Usage: translateBy vector polygon

Parameters:
Returns: Polygon2D<'Units, 'Coordinates>

Translate a polygon by the given displacement.

vector : Vector2D<'Units, 'Coordinates>
polygon : Polygon2D<'Units, 'Coordinates>
Returns: Polygon2D<'Units, 'Coordinates>

translateIn direction distance polygon

Full Usage: translateIn direction distance polygon

Parameters:
Returns: Polygon2D<'Units, 'Coordinates>

Translate a polygon in a given direction by a given distance.

direction : Direction2D<'Coordinates>
distance : Quantity<'Units>
polygon : Polygon2D<'Units, 'Coordinates>
Returns: Polygon2D<'Units, 'Coordinates>

vertices polygon

Full Usage: vertices polygon

Parameters:
Returns: Point2D<'Units, 'Coordinates> list

Get all vertices of a polygon; this will include vertices from the outer loop of the polygon and all inner loops. The order of the returned vertices is undefined.

polygon : Polygon2D<'Units, 'Coordinates>
Returns: Point2D<'Units, 'Coordinates> list

withHoles givenInnerLoops givenOuterLoop

Full Usage: withHoles givenInnerLoops givenOuterLoop

Parameters:
    givenInnerLoops : Point2D<'Units, 'Coordinates> list list
    givenOuterLoop : Point2D<'Units, 'Coordinates> list

Returns: Polygon2D<'Units, 'Coordinates>

Construct a polygon with holes from one outer loop and a list of inner loops. The loops must not touch or intersect each other. let outerLoop = [ Point2D.meters 0. 0. Point2D.meters 3. 0. Point2D.meters 3. 3. Point2D.meters 0. 3. ] let innerLoop = [ Point2D.meters 1. 1. Point2D.meters 1. 2. Point2D.meters 2. 2. Point2D.meters 2. 1. ] let squareWithHole = Polygon2D.withHoles [ innerLoop ] outerLoop As with `Polygon2D.singleLoop`, the last vertex of each loop is considered to be connected back to the first. Vertices of the outer loop should ideally be provided in counterclockwise order and vertices of the inner loops should ideally be provided in clockwise order.

givenInnerLoops : Point2D<'Units, 'Coordinates> list list
givenOuterLoop : Point2D<'Units, 'Coordinates> list
Returns: Polygon2D<'Units, 'Coordinates>