Description
The Distance
method calculates the shortest distance from a given point in 3D space to the line represented 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
Line line = new Line
{
Start = new Vector3(0, 0, 0),
End = new Vector3(10, 0, 0)
};
// 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 5 units away from the line on the Y-axis