float LengthSquared { get; set; }

robot_2Generated
code_blocksInput

Description

The LengthSquared property of the Vector2 struct returns the squared length (or magnitude) of the vector. This property is computationally faster than calculating the actual length using the Length property, as it avoids the square root operation. It is particularly useful in scenarios where the exact length is not necessary, such as when comparing distances.

Usage

Use the LengthSquared property when you need to compare the magnitudes of vectors or when the exact length is not required. This can improve performance in your application by avoiding the computational cost of a square root operation.

Example

Vector2 vector = new Vector2(3.0f, 4.0f);
float lengthSquared = vector.LengthSquared;
// lengthSquared will be 25.0f, which is 3^2 + 4^2