Vector3 ClosestPoint( Vector3& point )

book_4_sparkGenerated
code_blocksInput

Description

The ClosestPoint method of the BBox struct calculates the closest point on the bounding box to a given point in 3D space. This method is useful for determining the nearest point on the bounding box's surface to a specified point, which can be helpful in collision detection, physics calculations, or spatial queries.

Usage

To use the ClosestPoint method, you need to have an instance of BBox and a Vector3 point for which you want to find the closest point on the bounding box. The method will return a Vector3 representing the closest point on the bounding box.

Note that the input parameter point is passed by reference, which means the method can modify the original Vector3 object if needed.

Example

// Example usage of BBox.ClosestPoint
BBox boundingBox = new BBox(new Vector3(0, 0, 0), new Vector3(10, 10, 10));
Vector3 point = new Vector3(15, 5, 5);

// Find the closest point on the bounding box to the given point
Vector3 closestPoint = boundingBox.ClosestPoint(ref point);

// Output the closest point
// closestPoint should be (10, 5, 5) since the point is outside the box on the x-axis
Debug.Log($"Closest Point: {closestPoint}");