Class ShapeHelper
Approximates convex surfaces and calculates their bounds and mass properties.
public static class ShapeHelper
- Inheritance
-
ShapeHelper
- Inherited Members
Methods
CalculateBoundingBox<TSupport>(in TSupport, in JQuaternion, in JVector, out JBoundingBox)
Calculates the axis-aligned bounding box of a shape given its orientation and position.
public static void CalculateBoundingBox<TSupport>(in TSupport support, in JQuaternion orientation, in JVector position, out JBoundingBox box) where TSupport : ISupportMappable
Parameters
supportTSupportThe convex shape.
orientationJQuaternionThe orientation of the shape.
positionJVectorThe position of the shape.
boxJBoundingBoxThe resulting bounding box.
Type Parameters
TSupport
CalculateMassInertia<TSupport>(in TSupport, out JSymmetricMatrix, out JVector, out float, int)
Approximates a convex shape's mass, center of mass, and inertia at unit density.
public static void CalculateMassInertia<TSupport>(in TSupport support, out JSymmetricMatrix inertia, out JVector centerOfMass, out float mass, int subdivisions = 4) where TSupport : ISupportMappable
Parameters
supportTSupportThe convex shape.
inertiaJSymmetricMatrixThe inertia tensor about the local origin.
centerOfMassJVectorThe center of mass in local coordinates.
massfloatThe mass at unit density, equal to the shape's volume.
subdivisionsintSurface sampling detail; default is 4. Higher values increase accuracy and cost.
Type Parameters
TSupport
Remarks
Uses a triangle approximation of the surface. The inertia is about the shape's local origin, not its center of mass.
MakeHull(IEnumerable<JVector>, int)
[Obsolete("Use Tessellate instead.", true)]
public static List<JTriangle> MakeHull(IEnumerable<JVector> vertices, int subdivisions = 3)
Parameters
verticesIEnumerable<JVector>subdivisionsint
Returns
MakeHull(ReadOnlySpan<JVector>, int)
[Obsolete("Use Tessellate instead.", true)]
public static List<JTriangle> MakeHull(ReadOnlySpan<JVector> vertices, int subdivisions = 3)
Parameters
verticesReadOnlySpan<JVector>subdivisionsint
Returns
MakeHull<TSupport>(in TSupport, int)
[Obsolete("Use Tessellate instead.", true)]
public static List<JTriangle> MakeHull<TSupport>(in TSupport support, int subdivisions = 3) where TSupport : ISupportMappable
Parameters
supportTSupportsubdivisionsint
Returns
Type Parameters
TSupport
MakeHull<TSupport, TCollection>(in TSupport, TCollection, int)
[Obsolete("Use Tessellate instead.", true)]
public static void MakeHull<TSupport, TCollection>(in TSupport support, TCollection hullCollection, int subdivisions = 3) where TSupport : ISupportMappable where TCollection : class, ICollection<JTriangle>
Parameters
supportTSupporthullCollectionTCollectionsubdivisionsint
Type Parameters
TSupportTCollection
SampleHull(IEnumerable<JVector>, int)
Samples points on the convex hull of the supplied vertices.
public static List<JVector> SampleHull(IEnumerable<JVector> vertices, int subdivisions = 3)
Parameters
verticesIEnumerable<JVector>The vertices used to approximate the hull.
subdivisionsintSampling detail. Higher values sample more directions, at roughly four times the work per level. Default is 3.
Returns
Exceptions
- ArgumentException
Thrown when
verticesis empty.
SampleHull(ReadOnlySpan<JVector>, int)
Samples points on the convex hull of the supplied vertices.
public static List<JVector> SampleHull(ReadOnlySpan<JVector> vertices, int subdivisions = 3)
Parameters
verticesReadOnlySpan<JVector>The vertices used to approximate the hull.
subdivisionsintSampling detail. Higher values sample more directions, at roughly four times the work per level. Default is 3.
Returns
Exceptions
- ArgumentException
Thrown when
verticesis empty.
SampleHull<TSupport>(in TSupport, int)
Samples points on the surface of a convex shape.
public static List<JVector> SampleHull<TSupport>(in TSupport support, int subdivisions = 3) where TSupport : ISupportMappable
Parameters
supportTSupportThe convex shape.
subdivisionsintSampling detail. Higher values sample more directions, at roughly four times the work per level. Default is 3.
Returns
Type Parameters
TSupport
Tessellate(IEnumerable<JVector>, int)
Approximates the surface of the convex hull of the supplied vertices with triangles.
public static List<JTriangle> Tessellate(IEnumerable<JVector> vertices, int subdivisions = 3)
Parameters
verticesIEnumerable<JVector>The vertices used to approximate the hull.
subdivisionsintThe number of subdivisions used for hull generation.
Returns
Remarks
The surface may contain folds, overlapping triangles, or inward-facing normals, even for a smooth shape. Do not use these triangles to construct a ConvexHullShape. Each additional subdivision level increases the work roughly fourfold.
Exceptions
- ArgumentException
Thrown when
verticesis empty.
Tessellate(ReadOnlySpan<JVector>, int)
Approximates the surface of the convex hull of the supplied vertices with triangles.
public static List<JTriangle> Tessellate(ReadOnlySpan<JVector> vertices, int subdivisions = 3)
Parameters
verticesReadOnlySpan<JVector>The vertices used to approximate the hull.
subdivisionsintThe number of subdivisions used for hull generation.
Returns
Remarks
The surface may contain folds, overlapping triangles, or inward-facing normals, even for a smooth shape. Do not use these triangles to construct a ConvexHullShape. Each additional subdivision level increases the work roughly fourfold.
Exceptions
- ArgumentException
Thrown when
verticesis empty.
Tessellate<TSupport>(in TSupport, int)
Approximates a convex surface with triangles.
public static List<JTriangle> Tessellate<TSupport>(in TSupport support, int subdivisions = 3) where TSupport : ISupportMappable
Parameters
supportTSupportThe convex shape.
subdivisionsintSampling detail. Each level above 1 splits every triangle into four; the default of 3 splits twice.
Returns
Type Parameters
TSupport
Remarks
The surface may contain folds, overlapping triangles, or inward-facing normals, even for a smooth shape. Do not use these triangles to construct a ConvexHullShape. Each additional subdivision level increases the work roughly fourfold.
Tessellate<TSupport, TCollection>(in TSupport, TCollection, int)
Approximates a convex surface with triangles and appends them to the collection.
public static void Tessellate<TSupport, TCollection>(in TSupport support, TCollection hullCollection, int subdivisions = 3) where TSupport : ISupportMappable where TCollection : class, ICollection<JTriangle>
Parameters
supportTSupportThe convex shape.
hullCollectionTCollectionA collection to which the triangles are added.
subdivisionsintSampling detail. Each level above 1 splits every triangle into four; default is 3.
Type Parameters
TSupportTCollection
Remarks
The surface may contain folds, overlapping triangles, or inward-facing normals, even for a smooth shape. Do not use these triangles to construct a ConvexHullShape. Each additional subdivision level increases the work roughly fourfold.
Tessellate<TSupport, TSink>(in TSupport, ref TSink, int)
Approximates a convex surface with triangles and appends them to the sink.
public static void Tessellate<TSupport, TSink>(in TSupport support, ref TSink hullSink, int subdivisions = 3) where TSupport : ISupportMappable where TSink : ISink<JTriangle>
Parameters
supportTSupportThe convex shape.
hullSinkTSinkThe sink receiving the generated triangles.
subdivisionsintSampling detail. Each level above 1 splits every triangle into four; the default of 3 splits twice.
Type Parameters
TSupportThe support shape type.
TSinkThe sink type receiving the generated triangles.
Remarks
The surface may contain folds, overlapping triangles, or inward-facing normals, even for a smooth shape. Do not use these triangles to construct a ConvexHullShape. Each additional subdivision level increases the work roughly fourfold.