Description
The LengthSquared
property of the Vector3
struct provides the squared length of the vector. This property is useful for performance optimization when you need to compare vector lengths without computing the square root, which is required for the actual length. It is particularly beneficial in scenarios where only relative distances are needed, such as comparing which of two vectors is longer.
Usage
Use the LengthSquared
property when you need to compare the magnitude of vectors without the overhead of calculating the square root. This is especially useful in performance-critical code where you need to determine relative distances or lengths.
Example
Vector3 vector = new Vector3(3, 4, 0);
float squaredLength = vector.LengthSquared;
// squaredLength will be 25, which is 3*3 + 4*4 + 0*0