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.
| Argument | Type | Required | Description |
|---|---|---|---|
poly | Array<number> | Yes | - Array of point indices for the polygon |
points | vtkPoints | Yes | - vtkPoints instance |
centroid | Vector3 | No | - Optional output array (length 3) |
Returns
| Type | Description |
|---|---|
| Vector3 | The centroid as [x, y, z] |
extend
Method used to decorate a given object (publicAPI+model) with vtkPolygon characteristics.
| Argument | Type | Required | Description |
|---|---|---|---|
publicAPI | Yes | object on which methods will be bounds (public) | |
model | Yes | object on which data structure will be bounds (protected) | |
initialValues | IPolygonInitialValues | No | (default: {}) |
getPointArray
Get the array of triangles that triangulate the polygon.
newInstance
Method used to create a new instance of vtkPolygon.
| Argument | Type | Required | Description |
|---|---|---|---|
initialValues | IPolygonInitialValues | No | for 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.
| Argument | Type | Required | Description |
|---|---|---|---|
point | Vector3 | Yes | Point to check |
vertices | Array<Number> or TypedArray | Yes | Vertices of the polygon |
bounds | Bounds | Yes | Bounds of the vertices |
normal | Vector3 | Yes | Normal vector of the polygon |
Returns
| Type | Description |
|---|---|
| PolygonIntersectionState | Integer indicating the type of intersection |
setPoints
Set the polygon's points.
| Argument | Type | Required | Description |
|---|---|---|---|
points | Array[Vector3] | Yes | The 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.