Description
The SqrDistance
method calculates the squared distance from a given point in 3D space to the nearest point on the line. This method is useful for performance optimization when you only need to compare distances, as it avoids the computational cost of a square root operation.
Usage
To use the SqrDistance
method, you need to have an instance of the Line
struct. You can then call this method by passing a Vector3
representing the point from which you want to calculate the squared distance 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 3D space
Vector3 point = new Vector3(5, 5, 0);
// Calculate the squared distance from the point to the line
float squaredDistance = line.SqrDistance(point);
// Output the squared distance
// Note: Avoid using Console.WriteLine in s&box
// Instead, use the appropriate logging or debugging tools available in the environment
// Example: Log.Info($"Squared Distance: {squaredDistance}");