float Distance( Vector3 pos )
float Distance( Vector3 pos, Vector3& closestPoint )

book_4_sparkGenerated
code_blocksInput

Description

The Distance method calculates the shortest distance from a given point in 3D space to the line defined by the Line struct. This method is useful for determining how far a point is from the line, which can be critical in collision detection, physics calculations, or graphical applications.

Usage

To use the Distance method, you need to have an instance of the Line struct and a Vector3 representing the point from which you want to calculate the distance to the line. The method returns a float representing the shortest distance from the point to the line.

Example

// Create a line from point A to point B
Vector3 pointA = new Vector3(0, 0, 0);
Vector3 pointB = new Vector3(10, 0, 0);
Line line = new Line { Start = pointA, End = pointB };

// Define a point in space
Vector3 point = new Vector3(5, 5, 0);

// Calculate the distance from the point to the line
float distance = line.Distance(point);

// Output the distance
// The expected output is 5, as the point is directly above the midpoint of the line