float LengthSquared { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The LengthSquared property of the Vector4 struct provides the squared length (or magnitude) of the vector. This is calculated as the sum of the squares of its components (x, y, z, w). It is often used in performance-sensitive code where the actual length is not needed, as it avoids the computational cost of a square root operation.

Usage

Use the LengthSquared property when you need to compare vector lengths or when the exact length is not necessary. This can be particularly useful in scenarios such as collision detection or physics calculations where only relative lengths are important.

Example

Vector4 vector = new Vector4(3.0f, 4.0f, 0.0f, 0.0f);
float lengthSquared = vector.LengthSquared;
// lengthSquared will be 25.0f, as it is 3^2 + 4^2 + 0^2 + 0^2