FMath::Cos
#include "GenericPlatform/GenericPlatformMath.h"
Access: public
Specifiers: static
Description
Returns the cosine of an angle given in radians. A double overload exists for higher precision. Returns values in the range [-1, 1].
Signature
static UE_FORCEINLINE_HINT float Cos(float Value) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Value | float | Angle in radians. | — |
Return Type
float Caveats & Gotchas
- • Input is in radians, not degrees. Use FMath::DegreesToRadians to convert.
- • When computing both sine and cosine for the same angle (e.g. constructing a rotation matrix), use FMath::SinCos to compute both in a single call — it is significantly cheaper than two separate calls.
- • For large input values, floating-point precision degrades. If your angle accumulator grows over time (e.g. total elapsed time * frequency), wrap it with FMath::Fmod(Angle, 2*PI) periodically.
Example
Spawn actors in a circle using sin/cos C++
const int32 Count = 8;
const float Radius = 500.f;
for (int32 i = 0; i < Count; ++i)
{
float Angle = (2.f * PI * i) / Count;
FVector Offset(FMath::Cos(Angle) * Radius, FMath::Sin(Angle) * Radius, 0.f);
SpawnActorAt(GetActorLocation() + Offset);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?