Description
The LengthSquared
property of the Vector3Int
struct provides the squared length of the integer vector. This property is useful for performance optimization when comparing distances, as it avoids the computational cost of calculating the square root, which is required for the actual length. It is particularly beneficial when only the relative distances are needed, and the exact length is not necessary.
Usage
Use the LengthSquared
property when you need to compare the magnitudes of vectors without needing the exact length. This can be particularly useful in scenarios such as collision detection or when determining the closest object in a set, where only the relative distances matter.
Example
Vector3Int vector = new Vector3Int(3, 4, 5);
int squaredLength = vector.LengthSquared;
// squaredLength will be 50, as it is calculated as 3*3 + 4*4 + 5*5.