LYGIA Shader Library

cart2polar (lygia/space/cart2polar)

cartesian to polar transformation.

Use:

<vec2|vec3> cart2polar(<vec2|vec3> st)

Check it on Github


#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

Use:

<float2|float3> cart2polar(<float2|float3> st)

Check it on Github


#ifndef FNC_CART2POLAR
#define FNC_CART2POLAR

float2 cart2polar(in float2 st) {
    return float2(atan2(st.y, st.x), length(st));
}

// https://mathworld.wolfram.com/SphericalCoordinates.html
float3 cart2polar( in float3 st) {
    float r = length(st);
    float phi = acos(st.z/r);
    float theta = atan2(st.y, st.x);
    return float3(r, phi, theta);
}

#endif

Use:

<float2|float3> cart2polar(<float2|float3> st)

Check it on Github


#ifndef FNC_CART2POLAR
#define FNC_CART2POLAR

float2 cart2polar(float2 st) {
    return float2(atan2(st.y, st.x), length(st));
}

float3 cart2polar( float3 st ) {
    float r = length(st);
    float theta = acos(st.z/r);
    float phi = atan2(st.y, st.x);
    return float3(r, theta, phi);
}

#endif

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository