From cartesian to polar, on a 'wavy' sphere surface

88 Views Asked by At

For a hobby project I'm trying to transform a wavy halfsphere surface into smaller segments. For this I need to be able to go from cartesian coordinates to polar coordinates. One of the formulas for the waved surface looks like this:

x = radius * Math.cos(theta) * (Math.cos(phi) + (Math.cos(phi*9) / 10 ))

Now, a sensible first step would be to solve for phi, but I stumble on that plus sign. Any hints on how to solve this?

For your information, this is the grand scheme:

    mySuperQuadricSpec = {
        curve_X: function ( phi ) {
            x = Math.cos(phi) + ( Math.cos(phi*9) / 10 );
            return x;
        },
        curve_Y: function ( phi ) {
            y = Math.sin(phi) + ( Math.sin(phi*9) / 10 );
            return y;
        },
        modulator_XY: function ( theta ) {
            m_xy = Math.cos( theta );
            return m_xy;
        },
        modulator_Z: function ( theta ) {
            m_z = Math.sin( theta );
            return m_z;
        }
    };

in combination with:

    getX = function(phi_rad, theta_rad) {
        var x = radius * modulator_XY(theta_rad) * curve_X(phi_rad);
        return x;
    };

    getY = function(phi_rad, theta_rad) {
        var y = radius * modulator_XY(theta_rad) * curve_Y(phi_rad);
        return y;
    };

    getZ = function(theta_rad) {
        var z = radius * modulator_Z(theta_rad);
        return z;
    };