Spherical coordinates from Cartesian in negative space ?

Discussion in 'Plugin Development' started by Betagear, May 18, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Betagear

    Hi.
    I'm having a hard time trying to adapt my code to work in negative space : When x or z is negative, Theta is flipped, and if both are negative, Theta behaves normally.

    Code :

    Code:
        public void FromCartesian(Location loc){
            double x = loc.getX();
            double y = loc.getY();
            double z = loc.getZ();
            Rho = Math.sqrt(x*x + y*y + z*z);
            Theta = Math.atan(z/x);
            Phi = Math.acos(y/Rho);
        }
    Should I run just a dumb test for reversing Theta if x or z are negative or is there a proper mathematical solution to this ?

    EDIT : Actually, this is just X that is causing problem. Using a dumb test works, but isn't very mathematical.
     
    Last edited: May 18, 2016
  2. Offline

    mine-care

    @Betagear
    I am not quite sure what you the issue (after the edit) is :S
    I asume you are trying to create a spiral judging from the math, if you need help on that, there is a great tutorial in the resource section on how to make "3D particle helix" you may want to read :)
     
  3. Offline

    Betagear

    @mine-care Nope, i'm doing something even more complex : A patch of particules on the side of a sphere projected onto a cube. I wouldn't be mattering with Spherical Coordinates when I could have used Cylindrical Coordinates.
    The math is already done, all I need is Theta to not flip when X is negative.
     
  4. Offline

    ski23

    If you're doing anything like what I have tried to do in the past, you will have better look using a rotation matrix than spherical coordinates. Though theoretically both will work. I'll be releasing an api soon that will make your issue fairly simple.
     
Thread Status:
Not open for further replies.

Share This Page