float LengthSquared { get; set; }

robot_2Generated
code_blocksInput

Description

The LengthSquared property of the Vector2 struct provides the squared length (or magnitude) of the vector. This property is useful for performance optimization in scenarios where the actual length is not required, as it avoids the computational cost of a square root operation.

Usage

Use the LengthSquared property when you need to compare vector lengths or perform calculations where the exact length is not necessary. This can be particularly useful in physics calculations or when determining the relative size of vectors.

Example

// Example of using LengthSquared
Vector2 vector = new Vector2(3.0f, 4.0f);
float lengthSquared = vector.LengthSquared;

// Output: 25
// Explanation: The squared length of the vector (3, 4) is 3*3 + 4*4 = 9 + 16 = 25.