FMath::PolarToCartesian
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Converts polar coordinates (radius and angle in radians) to a 2D Cartesian coordinate pair. The inverse of CartesianToPolar.
Caveats & Gotchas
- • The angle parameter is in radians. Passing a degree value will produce wildly incorrect output — convert first with DegreesToRadians.
- • A FVector2D overload is available (PolarToCartesian(TVector2<T>, TVector2<T>&)) which may be more convenient when working with 2D vector types.
Signature
template<typename T>
static inline void PolarToCartesian(const T Rad, const T Ang, T& OutX, T& OutY) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Rad | const T | Radius (distance from origin). | — |
| Ang | const T | Angle in radians. | — |
| OutX | T& | Output Cartesian X coordinate. | — |
| OutY | T& | Output Cartesian Y coordinate. | — |
Return Type
void Example
Place objects in a circle given a radius and angle C++
float Radius = 500.f;
for (int32 i = 0; i < 8; ++i)
{
float Angle = FMath::DegreesToRadians(i * 45.f);
float X, Y;
FMath::PolarToCartesian(Radius, Angle, X, Y);
SpawnActorAt(FVector(X, Y, 0.f));
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?