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
bbBoundingBoxThe 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
minimumVector3The minimum vertex of the bounding box.
maximumVector3The 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
pointsVector3[]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
Transformation
The matrix which aligns and scales the box, and its translation vector represents the center of the box.
public Matrix4x4 Transformation
Field Value
Properties
Center
Returns the center of the OrientedBoundingBox.
public readonly Vector3 Center { get; }
Property Value
Size
The size of the OrientedBoundingBox if no scaling is applied to the transformation matrix.
public readonly Vector3 Size { get; }
Property Value
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
OBBOrientedBoundingBoxThe other OrientedBoundingBox to merge into this OrientedBoundingBox.
NoMatrixScaleAppliedboolIf 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
boxBoundingBoxThe 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
sphereBoundingSphereThe sphere to test.
IgnoreScaleboolOptimize 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
obbOrientedBoundingBoxThe 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
pointVector3The 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
pointVector3The 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
pointsVector3[]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
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
valueOrientedBoundingBoxThe Vector4 to compare with this instance.
Returns
Equals(ref OrientedBoundingBox)
Determines whether the specified Vector4 is equal to this instance.
public readonly bool Equals(ref OrientedBoundingBox value)
Parameters
valueOrientedBoundingBoxThe Vector4 to compare with this instance.
Returns
Equals(object?)
Determines whether the specified object is equal to this instance.
public override readonly bool Equals(object? value)
Parameters
Returns
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
AOrientedBoundingBoxThe source OrientedBoundingBox.
BOrientedBoundingBoxThe target OrientedBoundingBox.
NoMatrixScaleAppliedboolIf true, the method will use a fast algorithm which is inapplicable if a scale is applied to the transformation matrix of the OrientedBoundingBox.
Returns
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
rayRayThe 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
rayRayThe ray to test.
pointVector3When 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
AOrientedBoundingBoxThe OrientedBoundingBox to merge into it.
BOrientedBoundingBoxThe OrientedBoundingBox to be merged
NoMatrixScaleAppliedboolIf 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
OBBOrientedBoundingBoxThe other OrientedBoundingBox to merge into.
NoMatrixScaleAppliedboolIf 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
scalingVector3
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
scalingVector3
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
scalingfloat
ToString()
Returns a string that represents this instance.
public override readonly string ToString()
Returns
ToString(IFormatProvider)
Returns a string that represents this instance.
public readonly string ToString(IFormatProvider formatProvider)
Parameters
formatProviderIFormatProviderThe format provider.
Returns
ToString(string)
Returns a string that represents this instance.
public readonly string ToString(string format)
Parameters
formatstringThe format.
Returns
ToString(string?, IFormatProvider?)
Returns a string that represents this instance.
public readonly string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format.
formatProviderIFormatProviderThe format provider.
Returns
Transform(Matrix4x4)
Transforms this box using a transformation matrix.
public void Transform(Matrix4x4 mat)
Parameters
matMatrix4x4The 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
matMatrix4x4The 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
translationVector3the translation vector.
Translate(ref Vector3)
Translates the OrientedBoundingBox to a new position using a translation vector;
public void Translate(ref Vector3 translation)
Parameters
translationVector3the translation vector.
Operators
operator ==(OrientedBoundingBox, OrientedBoundingBox)
Tests for equality between two objects.
public static bool operator ==(OrientedBoundingBox left, OrientedBoundingBox right)
Parameters
leftOrientedBoundingBoxThe first value to compare.
rightOrientedBoundingBoxThe second value to compare.
Returns
- bool
trueiflefthas the same value asright; otherwise,false.
operator !=(OrientedBoundingBox, OrientedBoundingBox)
Tests for inequality between two objects.
public static bool operator !=(OrientedBoundingBox left, OrientedBoundingBox right)
Parameters
leftOrientedBoundingBoxThe first value to compare.
rightOrientedBoundingBoxThe second value to compare.
Returns
- bool
trueiflefthas a different value thanright; otherwise,false.