Description
The DistanceSquared
method calculates the squared distance between the current Vector3
instance and a target Vector3
. 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 required by the Distance
method.
Usage
To use the DistanceSquared
method, you need to have a Vector3
instance and a target Vector3
reference. The method will return a float
representing the squared distance between the two vectors.
Example
Vector3 pointA = new Vector3(1.0f, 2.0f, 3.0f);
Vector3 pointB = new Vector3(4.0f, 5.0f, 6.0f);
float squaredDistance = pointA.DistanceSquared(ref pointB);
// squaredDistance now holds the value 27.0f, which is the squared distance between pointA and pointB.