float DistanceSquared( Vector3& target )

book_4_sparkGenerated
code_blocksInput

Description

The DistanceSquared method calculates the squared distance between the current Vector3 instance and a specified target Vector3. This method is useful for performance optimization when comparing distances, as it avoids the computational cost of a square root operation required by the Distance method.

Usage

To use the DistanceSquared method, call it on an instance of Vector3 and pass a reference to another Vector3 as the target. The method will return a float representing the squared distance between the two vectors.

Example

Vector3 pointA = new Vector3(1.0f, 2.0f, 3.0f);
Vector3 pointB = new Vector3(4.0f, 5.0f, 6.0f);
float squaredDistance = pointA.DistanceSquared(ref pointB);
// squaredDistance now holds the value 27.0f, which is the squared distance between pointA and pointB.