Jump to content
• ### What is your GameDev Story?

• Advertisement

#### Archived

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

# Intersection of Line and Sphere

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

##### 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

##### 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

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 13
• 9
• 15
• 14
• 46
• Advertisement
• ### Forum Statistics

• Total Topics
634067
• Total Posts
3015325
×

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