Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Novalis

Intersection of Line and Sphere

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

Does anybody happen to know the equation for the intersection of a line and a sphere? I''m rendering a 3D sphere, and zooming in and out from it. When I zoom way in, it expands past the bounds of the screen, so I want to only calculate data for the parts that are visible. To do this I figured it would be best to find the 4 points at which the rays from the POV through the 4 corners of the screen intersect the sphere. I already have a function that can render a subsection of the sphere based on that information, but I don''t know how to get that information! Using x^2 + y^2 + z^2 = R^2 and ax + by + cz + d = 0 I''ve been able to break it down to a second order equation with only two variables, but I haven''t been able to take it any further... Any help would be appreciated!

Share this post


Link to post
Share on other sites
Advertisement
You should know that ax + by + cz + d = 0 is a plane equation. For a line you need the parametric form:

x = p + tv

where p is a vector from the origin to a point of the line. v is a vector in the direction of the the line. t is a real number. p and v are fixed and with different t values you can calculate each point x of the line. You can split this into three equations:

x = p.x + t*v.x
y = p.y + t*v.y
z = p.z + t*v.z

Then you have your sphere equation:

x^2 + y^2 + z^2 = R^2

So you have four equations and four unknown variables and you''ll be able to solve these equations.

Visit our homepage: www.rarebyte.de.st

GA

Share this post


Link to post
Share on other sites
Duh!

I''m such a moron! Thanks!

I''ve been working almost exclusively with polygons (ie bounded *planes*) for so long that I just slipped that plane equation in there without even thinking about it... Well, that solves my problem quite neatly.

Share this post


Link to post
Share on other sites

  • 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!