Share via


Vector2.DistanceSquared Method (Vector2%, Vector2%, Single%)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Calculates the distance between two vectors squared.

Namespace:  Microsoft.Xna.Framework
Assembly:  Microsoft.Xna.Framework.Math (in Microsoft.Xna.Framework.Math.dll)

Syntax

'Declaration
Public Shared Sub DistanceSquared ( _
    ByRef value1 As Vector2, _
    ByRef value2 As Vector2, _
    <OutAttribute> ByRef result As Single _
)
public static void DistanceSquared(
    ref Vector2 value1,
    ref Vector2 value2,
    out float result
)

Parameters

  • result
    Type: System.Single%
    [OutAttribute] The distance between the vectors squared.

Remarks

Distance is calculated with the formula:

sqrt((a – b)**2)

Distance squared is the value before taking the square root. Distance squared can often be used in place of distance if relative comparisons are being made. For example, consider three points A, B, and C. To determine whether B or C is further from A, compare the distance between A and B to the distance between A and C. Calculating the two distances involves two square roots, which are computationally expensive. However, using distance squared provides the same information and avoids calculating two square roots.

Version Information

Silverlight

Supported in: 5

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.