How to get my digestive system working again?

How can I get my Android camera coordinates system working like Google Earth's?

  • I'm implementing a touch screen interface whereby the user dragging their finger on the screen can rotate the camera in a sphere around the central point. My code works beautifully, but only covers 180degrees instead of the full 360. I used the article - http://en.wikipedia.org/wiki/Spherical_coordinate_system, specifically the Cartesian Coordinates section, to do this. I've posted my code below. Can anyone help get this working through the full 360 degrees on both axis? //Get current position oldX = getPosition().x; oldY = getPosition().y; oldZ = getPosition().z; //convert to inclination/azimuth camRadius = Math.sqrt((oldX * oldX) + (oldY * oldY) + (oldZ * oldZ)); inclinationTheta = Math.acos(oldZ / camRadius); azimuthPhi = Math.atan2(oldY,oldX); . . . //use touch screen changes (deltaTouchX and Y) inclinationTheta = (inclinationTheta + deltaTouchScreenX) % (2 * pi); azimuthPhi = (azimuthPhi + deltaTouchScreenY) % (2 * pi); //get new co-ordinates newX = camRadius * Math.sin(inclinationTheta) * Math.cos(azimuthPhi); newY = camRadius * Math.sin(inclinationTheta) * Math.sin(azimuthPhi); newZ = camRadius * Math.cos(inclinationTheta); //set new position setPosition(newX, newY, newZ);

  • Answer:

    I believe your problem is that the azimuth [math]\phi[/math] needs to range through the full 360°, but as the tangent function repeats with period 180°, arctan can only have a range of 180°. When [math]x=1[/math] and [math]y=-1[/math], you want [math]\phi = 315[/math], but your code will be giving you [math]\phi=135[/math] I'm no coder, but couldn't you detect if the y co-ordinate is less than 0, and if so add 180 to your value for [math]\phi[/math]? There still remains a problem when [math]y=0[/math], where you'll have to say [math]\phi = 0[/math] when [math]x>0[/math] and [math]\phi=180[/math] when [math]x<0[/math].

Richard Smeltzer at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.