Table of Contents

Struct OrientedBoundingBox

Namespace
HelixToolkit.Maths
Assembly
HelixToolkit.Maths.dll

OrientedBoundingBox (OBB) is a rectangular block, much like an AABB (BoundingBox) but with an arbitrary orientation.

public struct OrientedBoundingBox : IEquatable<OrientedBoundingBox>, IFormattable
Implements
Inherited Members
Extension Methods

Constructors

OrientedBoundingBox(BoundingBox)

Creates an OrientedBoundingBox from a BoundingBox.

public OrientedBoundingBox(BoundingBox bb)

Parameters

bb BoundingBox

The BoundingBox to create from.

Remarks

Initially, the OBB is axis-aligned box, but it can be rotated and transformed later.

OrientedBoundingBox(Vector3, Vector3)

Creates an OrientedBoundingBox which contained between two minimum and maximum points.

public OrientedBoundingBox(Vector3 minimum, Vector3 maximum)

Parameters

minimum Vector3

The minimum vertex of the bounding box.

maximum Vector3

The maximum vertex of the bounding box.

Remarks

Initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.

OrientedBoundingBox(Vector3[])

Creates an OrientedBoundingBox that fully contains the given points.

public OrientedBoundingBox(Vector3[] points)

Parameters

points Vector3[]

The points that will be contained by the box.

Remarks

This method is not for computing the best tight-fitting OrientedBoundingBox. And initially, the OrientedBoundingBox is axis-aligned box, but it can be rotated and transformed later.

Fields

Extents

Half lengths of the box along each axis.

public Vector3 Extents

Field Value

Vector3

Transformation

The matrix which aligns and scales the box, and its translation vector represents the center of the box.

public Matrix4x4 Transformation

Field Value

Matrix4x4

Properties

Center

Returns the center of the OrientedBoundingBox.

public readonly Vector3 Center { get; }

Property Value

Vector3

Size

The size of the OrientedBoundingBox if no scaling is applied to the transformation matrix.

public readonly Vector3 Size { get; }

Property Value

Vector3

Remarks

The property will return the actual size even if the scaling is applied using Scale method, but if the scaling is applied to transformation matrix, use GetSize Function instead.

Methods

Add(ref OrientedBoundingBox, bool)

Merge another OrientedBoundingBox into this OrientedBoundingBox.

public void Add(ref OrientedBoundingBox OBB, bool NoMatrixScaleApplied = false)

Parameters

OBB OrientedBoundingBox

The other OrientedBoundingBox to merge into this OrientedBoundingBox.

NoMatrixScaleApplied bool

If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.

Contains(ref BoundingBox)

Check the intersection between an OrientedBoundingBox and BoundingBox

public ContainmentType Contains(ref BoundingBox box)

Parameters

box BoundingBox

The BoundingBox to test.

Returns

ContainmentType

The type of containment the two objects have.

Remarks

For accuracy, The transformation matrix for the OrientedBoundingBox must not have any scaling applied to it. Anyway, scaling using Scale method will keep this method accurate.

Contains(BoundingSphere, bool)

Determines whether a OrientedBoundingBox contains a BoundingSphere.

public readonly ContainmentType Contains(BoundingSphere sphere, bool IgnoreScale = false)

Parameters

sphere BoundingSphere

The sphere to test.

IgnoreScale bool

Optimize the check operation by assuming that OrientedBoundingBox has no scaling applied

Returns

ContainmentType

The type of containment the two objects have.

Remarks

This method is not designed for OrientedBoundingBox which has a non-uniform scaling applied to its transformation matrix. But any type of scaling applied using Scale method will keep this method accurate.

Contains(ref OrientedBoundingBox)

Check the intersection between two OrientedBoundingBox

public ContainmentType Contains(ref OrientedBoundingBox obb)

Parameters

obb OrientedBoundingBox

The OrientedBoundingBoxs to test.

Returns

ContainmentType

The type of containment the two objects have.

Remarks

For accuracy, The transformation matrix for both OrientedBoundingBox must not have any scaling applied to it. Anyway, scaling using Scale method will keep this method accurate.

Contains(Vector3)

Determines whether a OrientedBoundingBox contains a point.

public readonly ContainmentType Contains(Vector3 point)

Parameters

point Vector3

The point to test.

Returns

ContainmentType

The type of containment the two objects have.

Contains(ref Vector3)

Determines whether a OrientedBoundingBox contains a point.

public readonly ContainmentType Contains(ref Vector3 point)

Parameters

point Vector3

The point to test.

Returns

ContainmentType

The type of containment the two objects have.

Contains(Vector3[])

Determines whether a OrientedBoundingBox contains an array of points>.

public readonly ContainmentType Contains(Vector3[] points)

Parameters

points Vector3[]

The points array to test.

Returns

ContainmentType

The type of containment.

ContainsLine(ref Vector3, ref Vector3)

Check the intersection between an OrientedBoundingBox and a line defined by two points

public readonly ContainmentType ContainsLine(ref Vector3 L1, ref Vector3 L2)

Parameters

L1 Vector3

The first point in the line.

L2 Vector3

The second point in the line.

Returns

ContainmentType

The type of containment the two objects have.

Remarks

For accuracy, The transformation matrix for the OrientedBoundingBox must not have any scaling applied to it. Anyway, scaling using Scale method will keep this method accurate.

Equals(OrientedBoundingBox)

Determines whether the specified Vector4 is equal to this instance.

public readonly bool Equals(OrientedBoundingBox value)

Parameters

value OrientedBoundingBox

The Vector4 to compare with this instance.

Returns

bool

true if the specified Vector4 is equal to this instance; otherwise, false.

Equals(ref OrientedBoundingBox)

Determines whether the specified Vector4 is equal to this instance.

public readonly bool Equals(ref OrientedBoundingBox value)

Parameters

value OrientedBoundingBox

The Vector4 to compare with this instance.

Returns

bool

true if the specified Vector4 is equal to this instance; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to this instance.

public override readonly bool Equals(object? value)

Parameters

value object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetBoundingBox()

Get the axis-aligned BoundingBox which contains all OrientedBoundingBox corners.

public readonly BoundingBox GetBoundingBox()

Returns

BoundingBox

The axis-aligned BoundingBox of this OrientedBoundingBox.

GetBoxToBoxMatrix(ref OrientedBoundingBox, ref OrientedBoundingBox, bool)

Calculates the matrix required to transfer any point from one OrientedBoundingBox local coordinates to another.

public static Matrix4x4 GetBoxToBoxMatrix(ref OrientedBoundingBox A, ref OrientedBoundingBox B, bool NoMatrixScaleApplied = false)

Parameters

A OrientedBoundingBox

The source OrientedBoundingBox.

B OrientedBoundingBox

The target OrientedBoundingBox.

NoMatrixScaleApplied bool

If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.

Returns

Matrix4x4

GetCorners()

Retrieves the eight corners of the bounding box.

public readonly Vector3[] GetCorners()

Returns

Vector3[]

An array of points representing the eight corners of the bounding box.

GetHashCode()

Returns a hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

GetSize()

Returns the size of the OrientedBoundingBox taking into consideration the scaling applied to the transformation matrix.

public readonly Vector3 GetSize()

Returns

Vector3

The size of the consideration

Remarks

This method is computationally expensive, so if no scale is applied to the transformation matrix use Size property instead.

GetSizeSquared()

Returns the square size of the OrientedBoundingBox taking into consideration the scaling applied to the transformation matrix.

public readonly Vector3 GetSizeSquared()

Returns

Vector3

The size of the consideration

Intersects(ref Ray)

Determines whether there is an intersection between a Ray and a OrientedBoundingBox.

public bool Intersects(ref Ray ray)

Parameters

ray Ray

The ray to test.

Returns

bool

Whether the two objects intersected.

Intersects(ref Ray, out Vector3)

Determines whether there is an intersection between a Ray and a OrientedBoundingBox.

public bool Intersects(ref Ray ray, out Vector3 point)

Parameters

ray Ray

The ray to test.

point Vector3

When the method completes, contains the point of intersection, or Zero if there was no intersection.

Returns

bool

Whether the two objects intersected.

Merge(ref OrientedBoundingBox, ref OrientedBoundingBox, bool)

Merge an OrientedBoundingBox B into another OrientedBoundingBox A, by expanding A to contain B and keeping A orientation.

public static void Merge(ref OrientedBoundingBox A, ref OrientedBoundingBox B, bool NoMatrixScaleApplied = false)

Parameters

A OrientedBoundingBox

The OrientedBoundingBox to merge into it.

B OrientedBoundingBox

The OrientedBoundingBox to be merged

NoMatrixScaleApplied bool

If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.

Remarks

Unlike merging axis aligned boxes, The operation is not interchangeable, because it keeps A orientation and merge B into it.

MergeInto(ref OrientedBoundingBox, bool)

Merge this OrientedBoundingBox into another OrientedBoundingBox, keeping the other OrientedBoundingBox orientation.

public void MergeInto(ref OrientedBoundingBox OBB, bool NoMatrixScaleApplied = false)

Parameters

OBB OrientedBoundingBox

The other OrientedBoundingBox to merge into.

NoMatrixScaleApplied bool

If true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.

Scale(Vector3)

Scales the OrientedBoundingBox by scaling its Extents without affecting the Transformation matrix, By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate.

public void Scale(Vector3 scaling)

Parameters

scaling Vector3

Scale(ref Vector3)

Scales the OrientedBoundingBox by scaling its Extents without affecting the Transformation matrix, By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate.

public void Scale(ref Vector3 scaling)

Parameters

scaling Vector3

Scale(float)

Scales the OrientedBoundingBox by scaling its Extents without affecting the Transformation matrix, By keeping Transformation matrix scaling-free, the collision detection methods will be more accurate.

public void Scale(float scaling)

Parameters

scaling float

ToString()

Returns a string that represents this instance.

public override readonly string ToString()

Returns

string

A string that represents this instance.

ToString(IFormatProvider)

Returns a string that represents this instance.

public readonly string ToString(IFormatProvider formatProvider)

Parameters

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToString(string)

Returns a string that represents this instance.

public readonly string ToString(string format)

Parameters

format string

The format.

Returns

string

A string that represents this instance.

ToString(string?, IFormatProvider?)

Returns a string that represents this instance.

public readonly string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format.

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

Transform(Matrix4x4)

Transforms this box using a transformation matrix.

public void Transform(Matrix4x4 mat)

Parameters

mat Matrix4x4

The transformation matrix.

Remarks

While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy.

Transform(ref Matrix4x4)

Transforms this box using a transformation matrix.

public void Transform(ref Matrix4x4 mat)

Parameters

mat Matrix4x4

The transformation matrix.

Remarks

While any kind of transformation can be applied, it is recommended to apply scaling using scale method instead, which scales the Extents and keeps the Transformation matrix for rotation only, and that preserves collision detection accuracy.

Translate(Vector3)

Translates the OrientedBoundingBox to a new position using a translation vector;

public void Translate(Vector3 translation)

Parameters

translation Vector3

the translation vector.

Translate(ref Vector3)

Translates the OrientedBoundingBox to a new position using a translation vector;

public void Translate(ref Vector3 translation)

Parameters

translation Vector3

the translation vector.

Operators

operator ==(OrientedBoundingBox, OrientedBoundingBox)

Tests for equality between two objects.

public static bool operator ==(OrientedBoundingBox left, OrientedBoundingBox right)

Parameters

left OrientedBoundingBox

The first value to compare.

right OrientedBoundingBox

The second value to compare.

Returns

bool

true if left has the same value as right; otherwise, false.

operator !=(OrientedBoundingBox, OrientedBoundingBox)

Tests for inequality between two objects.

public static bool operator !=(OrientedBoundingBox left, OrientedBoundingBox right)

Parameters

left OrientedBoundingBox

The first value to compare.

right OrientedBoundingBox

The second value to compare.

Returns

bool

true if left has a different value than right; otherwise, false.