The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
This topic has not yet been rated - Rate this topic

# XMVector2Normalize method

Returns the normalized version of a 2D vector.

### Syntax

```
XMVECTOR XMVector2Normalize(
[in]  XMVECTOR V
);

```

V [in]

2D vector.

### Return value

Returns the normalized version of V.

### Remarks

For a vector of length 0, this function returns a zero vector. For a vector with infinite length, it returns a vector of QNaN.

Note that for most graphics applications, ensuring the vectors have well-defined lengths that don't cause problems for normalization is common practice. However, if you need a robust normalization that works for all floating-point inputs, you can use the following code instead:

```

inline XMVECTOR XMVector2NormalizeRobust( FXMVECTOR V )
{
// Compute the maximum absolute value component.
XMVECTOR vAbs = XMVectorAbs(V);
XMVECTOR max0 = XMVectorSplatX(vAbs);
XMVECTOR max1 = XMVectorSplatY(vAbs);
max0 = XMVectorMax(max0, max1);

// Divide by the maximum absolute component.
XMVECTOR normalized = XMVectorDivide(V, max0);

// Set to zero when the original length is zero.

XMVECTOR t0 = XMVector2LengthSq(normalized);
XMVECTOR length = XMVectorSqrt(t0);

// Divide by the length to normalize.
normalized = XMVectorDivide(normalized, length);

// Set to zero when the original length is zero or infinity.  In the
// latter case, this is considered to be an unexpected condition.
return normalized;
}

```

#### Platform Requirements

Microsoft Visual Studio 2010 or Microsoft Visual Studio 2012 with the Windows SDK for Windows 8. Supported for Win32 desktop apps, Windows Store apps, and Windows Phone 8 apps.

### Requirements

 Namespace Use DirectX. DirectXMath.h

XMVector2NormalizeEst