Jump to content
  • Advertisement
Sign in to follow this  
smc

Sphere point to circle point

This topic is 3122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a vector which can point to any coordinate on the top half of a unit sphere. The vector location is generated from accelerometer data. I am trying to project the position into a circle on a plane. Problem: I naively used a simple projection onto the x,y plane. As the vector approaches the x,y plane the distance traveled on the sphere surface does not correspond to the distance traveled on the x,y plane. My rusty math skills are showing. What I would like to do is project these points to a 'flattened' sphere. It would be nice if the point distance distribution was linear. For some reason I am coming up empty. I end up converting to cartesian which I do not want. Any pointers would be very helpful. Edit:<bad idea removed> [Edited by - smc on May 3, 2010 9:13:02 PM]

Share this post


Link to post
Share on other sites
Advertisement
I don't have a solution for you, but here's an idea that might be a little closer to what you're looking for than what you have now. (Note: all code examples are off the top and my head and untested.)

First, convert the point on the hemisphere to spherical coordinates:
float theta = 0;
float l = sqrt(x * x + y * y);
if (l > epsilon) {
theta = atan2(y, x);
}
float phi = pi_over_2 - atan2(z, l);
Map phi to the range [0, 1]:
float t = phi / pi_over_2;
Generate the final x, y position using a polar coordinate conversion:
circle_x = cos(theta) * t;
circle_y = sin(theta) * t;
Anyway, that's what first comes to mind, but maybe someone else can offer a better solution.

[Edit: Fixed error in pseudocode.]

[Edited by - jyk on May 4, 2010 12:40:06 PM]

Share this post


Link to post
Share on other sites
Thank you. This works very good. Mapping to PI_OVER_2 is all I needed to change.

Share this post


Link to post
Share on other sites
Quote:
Mapping to PI_OVER_2 is all I needed to change.
Oops, fixed - not sure what I was thinking there :-|

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!