float LengthSquared { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The LengthSquared property of the Vector2 struct provides 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 computational cost of a square root operation. It is particularly useful in scenarios where only a relative comparison of vector lengths is needed, such as when determining which of two vectors is longer.

Usage

Use the LengthSquared property when you need to compare the lengths of vectors or when the exact length is not necessary. This can improve performance in your application by reducing the number of square root calculations.

Example

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