Jump to content
  • Advertisement
Sign in to follow this  
bimm

simple math problem

This topic is 2463 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

unfortunately my math skill is a bit lacking

I need to find the latitude and longitude of the intersection of a ray coming from the center of a sphere to the radius/surface.

What I have right now is lat=atan(z,x) and lon=asin(y) (after normalization)

Now this doesn't provide a very convincing sky-sphere, since usually you aren't in the core of the earth. What I want to do is move the origin of the ray upward closer to the surface. I guess this only changes the longitude, and it can be computed with a table.

I just need a formula to convert angle a to b, http://imageshack.us.../problem1a.png/

edit: and what is known is 'a' (or the actual ray), the radius of the sphere, and Y or height of the ray from the center of the circle

Share this post


Link to post
Share on other sites
Advertisement
Intersect the ray with the sphere, then use the formulas you already have to compute latitude and longitude.

Share this post


Link to post
Share on other sites
Hi Bimm,

You can determine 'b' using the law of sines. From your figure this can be expressed as,

R * sin( c) = Y * sin(pi/2 + a)

where 'c' is the angle opposite the side of length, Y. Rearranging the above expression gives,

c = asin(Y * sin(pi/2 + a) / R).

Since the internal angles of a triangle add up to pi (or 180 degrees if you prefer), we can determine b

b = a - pi/2 + asin(Y * sin(pi/2 + a) / R)

-Josh

Share this post


Link to post
Share on other sites
Thanks a lot, this is much better than the code I shoveled into my shader... I didn't even notice that my figure was actually a triangle lol

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!