fuckingtech/public/assets/glsl/lygia/space/cart2polar.glsl
Elias Rhouzlane bf76c6b086 fix: code
2025-04-06 17:23:52 +02:00

22 lines
No EOL
495 B
GLSL

/*
contributors: [Ivan Dianov, Kathy McGuiness]
description: cartesian to polar transformation.
use: <vec2|vec3> cart2polar(<vec2|vec3> st)
*/
#ifndef FNC_CART2POLAR
#define FNC_CART2POLAR
vec2 cart2polar(in vec2 st) {
return vec2(atan(st.y, st.x), length(st));
}
// https://mathworld.wolfram.com/SphericalCoordinates.html
vec3 cart2polar( in vec3 st ) {
float r = length(st);
float phi = acos(st.z/r);
float theta = atan(st.y, st.x);
return vec3(r, phi, theta);
}
#endif