Skip to content

Polygon

Introduction

vtkPolygon represents a 2D n-sided polygon.

The polygons cannot have any internal holes, and cannot self-intersect. Define the polygon with n-points ordered in the counter-clockwise direction. Do not repeat the last point.

Methods

computeCentroid

Compute the centroid of a polygon.

ArgumentTypeRequiredDescription
polyArray<number>Yes- Array of point indices for the polygon
pointsvtkPointsYes- vtkPoints instance
centroidVector3No- Optional output array (length 3)

Returns

TypeDescription
Vector3The centroid as [x, y, z]

extend

Method used to decorate a given object (publicAPI+model) with vtkPolygon characteristics.

ArgumentTypeRequiredDescription
publicAPIYesobject on which methods will be bounds (public)
modelYesobject on which data structure will be bounds (protected)
initialValuesIPolygonInitialValuesNo(default: {})

getPointArray

Get the array of triangles that triangulate the polygon.

newInstance

Method used to create a new instance of vtkPolygon.

ArgumentTypeRequiredDescription
initialValuesIPolygonInitialValuesNofor pre-setting some of its content

pointInPolygon

Determine whether a point is inside a polygon. The function uses a winding number calculation generalized to the 3D plane one which the polygon resides. Returns 0 if point is not in the polygon; 1 if it is inside. Can also return -1 to indicate a degenerate polygon. This implementation is inspired by Dan Sunday's algorithm found in the book Practical Geometry Algorithms.

ArgumentTypeRequiredDescription
pointVector3YesPoint to check
verticesArray<Number> or TypedArrayYesVertices of the polygon
boundsBoundsYesBounds of the vertices
normalVector3YesNormal vector of the polygon

Returns

TypeDescription
PolygonIntersectionStateInteger indicating the type of intersection

setPoints

Set the polygon's points.

ArgumentTypeRequiredDescription
pointsArray[Vector3]YesThe polygon's points.

triangulate

Triangulate this polygon. The output data must be accessed through getPointArray. The output data contains points by group of three: each three-group defines one triangle.