# [name]

A convex hull class. Implements the Quickhull algorithm by: Dirk Gregorius. March 2014, Game Developers Conference: [link:http://media.steampowered.com/apps/valve/2014/DirkGregorius_ImplementingQuickHull.pdf Implementing QuickHull].

## Import

[name] is an add-on, and must be imported explicitly. See [link:#manual/introduction/Installation Installation / Addons].

`import { ConvexHull } from 'three/addons/math/ConvexHull.js';`

## Constructor

### [name]()

Creates a new instance of [name].

## Properties

### [property:VertexList assigned]

This [page:VertexList vertex list] holds all vertices that are assigned to a face. Default is an empty vertex list.

### [property:Array faces]

The generated faces of the convex hull. Default is an empty array.

### [property:Array newFaces]

This array holds the faces that are generated within a single iteration. Default is an empty array.

### [property:Float tolerance]

The epsilon value that is used for internal comparative operations. The calculation of this value depends on the size of the geometry. Default is -1.

### [property:VertexList unassigned]

This [page:VertexList vertex list] holds all vertices that are not assigned to a face. Default is an empty vertex list.

### [property:Array vertices]

The internal representation of the given geometry data (an array of [page:VertexNode vertices]).

## Methods

### [method:HalfEdge addAdjoiningFace]( [param:VertexNode eyeVertex], [param:HalfEdge horizonEdge] )

[page:VertexNode eyeVertex] - The vertex that is added to the hull.
[page:HalfEdge horizonEdge] - A single edge of the horizon.
Creates a face with the vertices 'eyeVertex.point', 'horizonEdge.tail' and 'horizonEdge.head' in CCW order. All the half edges are created in CCW order thus the face is always pointing outside the hull

### [method:this addNewFaces]( [param:VertexNode eyeVertex], [param:HalfEdge horizonEdge] )

[page:VertexNode eyeVertex] - The vertex that is added to the hull.
[page:HalfEdge horizon] - An array of half-edges that form the horizon.
Adds 'horizon.length' faces to the hull, each face will be linked with the horizon opposite face and the face on the left/right.

### [method:this addVertexToFace]( [param:VertexNode vertex], [param:Face face] )

[page:VertexNodeNode vertex] - The vertex to add.
[page:Face face] - The target face.
Adds a vertex to the 'assigned' list of vertices and assigns it to the given face.

### [method:this addVertexToHull]( [param:VertexNode eyeVertex] )

[page:VertexNode eyeVertex] - The vertex that is added to the hull.
Adds a vertex to the hull with the following algorithm

- Compute the 'horizon' which is a chain of half edges. For an edge to belong to this group it must be the edge connecting a face that can see 'eyeVertex' and a face which cannot see 'eyeVertex'.
- All the faces that can see 'eyeVertex' have its visible vertices removed from the assigned vertex list.
- A new set of faces is created with each edge of the 'horizon' and 'eyeVertex'. Each face is connected with the opposite horizon face and the face on the left/right.
- The vertices removed from all the visible faces are assigned to the new faces if possible.

### [method:this cleanup]()

Cleans up internal properties after computing the convex hull.

### [method:this compute]()

Starts the execution of the quick hull algorithm.

### [method:Object computeExtremes]()

Computes the extremes values (min/max vectors) which will be used to compute the initial hull.

### [method:this computeHorizon]( [param:Vector3 eyePoint], [param:HalfEdge crossEdge], [param:Face face], [param:Array horizon] )

[page:Vector3 eyePoint] - The 3D-coordinates of a point.
[page:HalfEdge crossEdge] - The edge used to jump to the current face.
[page:Face face] - The current face being tested.
[page:Array horizon] - The edges that form part of the horizon in CCW order.
Computes a chain of half edges in CCW order called the 'horizon'. For an edge to be part of the horizon it must join a face that can see 'eyePoint' and a face that cannot see 'eyePoint'.

### [method:this computeInitialHull]()

Computes the initial simplex assigning to its faces all the points that are candidates to form part of the hull.

### [method:this containsPoint]( [param:Vector3 point] )

[page:Vector3 point] - A point in 3D space.
Returns `true` if the given point is inside this convex hull.

### [method:this deleteFaceVertices]( [param:Face face], [param:Face absorbingFace] )

[page:Face face] - The given face.
[page:Face absorbingFace] - An optional face that tries to absorb the vertices of the first face.
Removes all the visible vertices that 'face' is able to see.

- If 'absorbingFace' doesn't exist, then all the removed vertices will be added to the 'unassigned' vertex list.
- If 'absorbingFace' exists, then this method will assign all the vertices of 'face' that can see 'absorbingFace'.
- If a vertex cannot see 'absorbingFace', it's added to the 'unassigned' vertex list.

### [method:Vector3 intersectRay]( [param:Ray ray], [param:Vector3 target] )

[page:Ray ray] - The given ray.
[page:Vector3 target] - The target vector representing the intersection point.
Performs a ray intersection test with this convext hull. If no intersection is found, `null` is returned.

### [method:Boolean intersectsRay]( [param:Ray ray] )

[page:Ray ray] - The given ray.
Returns `true` if the given ray intersects with this convex hull.

### [method:this makeEmpty]()

Makes this convex hull empty.

### [method:VertexNode nextVertexToAdd]()

Finds the next vertex to create faces with the current hull.

- Let the initial face be the first face existing in the 'assigned' vertex list.
- If a face doesn't exist then return since there're no vertices left.
- Otherwise for each vertex that face sees find the one furthest away from it.

### [method:this reindexFaces]()

Removes inactive (e.g. deleted) faces from the internal face list.

### [method:VertexNode removeAllVerticesFromFace]( [param:Face face] )

[page:Face face] - The given face.
Removes all the visible vertices that a given face is able to see which are stored in the 'assigned' vertex list.

### [method:this removeVertexFromFace]( [param:VertexNode vertex], [param:Face face] )

[page:VertexNode vertex] - The vertex to remove.
[page:Face face] - The target face.
Removes a vertex from the 'assigned' list of vertices and from the given face. It also makes sure that the link from 'face' to the first vertex it sees in 'assigned' is linked correctly after the removal.

### [method:this resolveUnassignedPoints]( [param:Array newFaces] )

[page:Face newFaces] - An array of new faces.
Reassigns as many vertices as possible from the unassigned list to the new faces.

### [method:this setFromObject]( [param:Object3D object] )

[page:Object3D object] - [page:Object3D] to compute the convex hull of.
Computes the convex hull of an [page:Object3D] (including its children),accounting for the world transforms of both the object and its childrens.

### [method:this setFromPoints]( [param:Array points] )

[page:Array points] - Array of [page:Vector3 Vector3s] that the resulting convex hull will contain.
Computes to convex hull for the given array of points.

## Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/math/ConvexHull.js examples/jsm/math/ConvexHull.js]