Description
The DistanceSquared
method calculates the squared distance between two 2D vectors. This method is useful when you need to compare distances without the computational cost of a square root operation, which is required for calculating the actual distance. The squared distance is often used in performance-critical code where the exact distance is not necessary, but relative distances are.
Usage
To use the DistanceSquared
method, pass two Vector2
references as parameters. The method will return a float
representing the squared distance between the two vectors.
Example usage:
Vector2 pointA = new Vector2(1.0f, 2.0f);
Vector2 pointB = new Vector2(4.0f, 6.0f);
float squaredDistance = Vector2.DistanceSquared(ref pointA, ref pointB);
Example
Vector2 pointA = new Vector2(1.0f, 2.0f);
Vector2 pointB = new Vector2(4.0f, 6.0f);
float squaredDistance = Vector2.DistanceSquared(ref pointA, ref pointB);