Table of Contents

Class ShapeHelper

Namespace
Jitter2.Collision.Shapes
Assembly
Jitter2.dll

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

support TSupport

The convex shape.

orientation JQuaternion

The orientation of the shape.

position JVector

The position of the shape.

box JBoundingBox

The 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

support TSupport

The convex shape.

inertia JSymmetricMatrix

The inertia tensor about the local origin.

centerOfMass JVector

The center of mass in local coordinates.

mass float

The mass at unit density, equal to the shape's volume.

subdivisions int

Surface 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

vertices IEnumerable<JVector>
subdivisions int

Returns

List<JTriangle>

MakeHull(ReadOnlySpan<JVector>, int)

[Obsolete("Use Tessellate instead.", true)]
public static List<JTriangle> MakeHull(ReadOnlySpan<JVector> vertices, int subdivisions = 3)

Parameters

vertices ReadOnlySpan<JVector>
subdivisions int

Returns

List<JTriangle>

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

support TSupport
subdivisions int

Returns

List<JTriangle>

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

support TSupport
hullCollection TCollection
subdivisions int

Type Parameters

TSupport
TCollection

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

vertices IEnumerable<JVector>

The vertices used to approximate the hull.

subdivisions int

Sampling detail. Higher values sample more directions, at roughly four times the work per level. Default is 3.

Returns

List<JVector>

Sampled surface points in local coordinates, with exact duplicates removed.

Exceptions

ArgumentException

Thrown when vertices is 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

vertices ReadOnlySpan<JVector>

The vertices used to approximate the hull.

subdivisions int

Sampling detail. Higher values sample more directions, at roughly four times the work per level. Default is 3.

Returns

List<JVector>

Sampled surface points in local coordinates, with exact duplicates removed.

Exceptions

ArgumentException

Thrown when vertices is 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

support TSupport

The convex shape.

subdivisions int

Sampling detail. Higher values sample more directions, at roughly four times the work per level. Default is 3.

Returns

List<JVector>

Sampled surface points in local coordinates, with exact duplicates removed.

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

vertices IEnumerable<JVector>

The vertices used to approximate the hull.

subdivisions int

The number of subdivisions used for hull generation.

Returns

List<JTriangle>

A list of triangles representing the convex hull.

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 vertices is 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

vertices ReadOnlySpan<JVector>

The vertices used to approximate the hull.

subdivisions int

The number of subdivisions used for hull generation.

Returns

List<JTriangle>

A list of triangles representing the convex hull.

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 vertices is 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

support TSupport

The convex shape.

subdivisions int

Sampling detail. Each level above 1 splits every triangle into four; the default of 3 splits twice.

Returns

List<JTriangle>

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

support TSupport

The convex shape.

hullCollection TCollection

A collection to which the triangles are added.

subdivisions int

Sampling detail. Each level above 1 splits every triangle into four; default is 3.

Type Parameters

TSupport
TCollection

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

support TSupport

The convex shape.

hullSink TSink

The sink receiving the generated triangles.

subdivisions int

Sampling detail. Each level above 1 splits every triangle into four; the default of 3 splits twice.

Type Parameters

TSupport

The support shape type.

TSink

The 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.