FMath::CartesianToPolar
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Converts a 2D Cartesian coordinate pair to polar form (radius and angle). A FVector2D overload is also available that accepts and returns TVector2.
Caveats & Gotchas
- • The output angle OutAng is in radians in the range [-π, π] (the range of Atan2). Convert to degrees with RadiansToDegrees if your downstream code expects degrees.
- • Passing (0, 0) returns radius 0 and angle 0 — Atan2(0,0) is defined as 0 in UE's implementation, so no special-case handling is needed.
Signature
template<typename T>
static inline void CartesianToPolar(const T X, const T Y, T& OutRad, T& OutAng) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | const T | Cartesian X coordinate. | — |
| Y | const T | Cartesian Y coordinate. | — |
| OutRad | T& | Output radius (distance from origin). | — |
| OutAng | T& | Output angle in radians, in the range [-π, π]. | — |
Return Type
void Example
Convert a 2D velocity to speed and heading C++
FVector2D Vel(VelocityX, VelocityY);
float Speed, HeadingRad;
FMath::CartesianToPolar(Vel.X, Vel.Y, Speed, HeadingRad);
float HeadingDeg = FMath::RadiansToDegrees(HeadingRad); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?