Created
February 6, 2024 07:17
-
-
Save Fewes/427ec9097d37ba955e32ca0a7553f612 to your computer and use it in GitHub Desktop.
Polar/spherical coordinates conversion functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef POLAR_INCLUDED | |
#define POLAR_INCLUDED | |
#define PI 3.14159265359 | |
float2 UVToPolar(float2 uv) | |
{ | |
return float2(uv.x * (2 * PI), (uv.y - 0.5) * PI); | |
} | |
float2 PolarToUV(float2 polar) | |
{ | |
return float2(polar.x / (2 * PI), polar.y / PI + 0.5); | |
} | |
float3 PolarToCartesian(float2 polar) | |
{ | |
return float3( | |
cos(polar.x) * cos(polar.y), | |
sin(polar.y), | |
sin(polar.x) * cos(polar.y) | |
); | |
} | |
float2 CartesianToPolar(float3 cartesian) | |
{ | |
return float2( | |
atan2(cartesian.z, cartesian.x), | |
asin(cartesian.y) | |
); | |
} | |
#endif // POLAR_INCLUDED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment