Description
The SqrDistance
method calculates the squared distance from a given point in 3D space to the line defined by the Line
struct. This method is useful for performance optimization when comparing distances, as it avoids the computational cost of a square root operation required by the Distance
method.
Usage
To use the SqrDistance
method, you need to have an instance of the Line
struct and a Vector3
representing the point from which you want to calculate the squared distance to the line. The method returns a float
representing the squared distance.
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}");