#### Archived

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

# ray/sphere intersection

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

## Recommended Posts

Im having a problem with ray/sphere intersection math. I have programmed the intersection code the geometric way as its faster and makes more sence. But now im trying to test it and I keep getting unreal roots when trying to solve the equation. heres a very asic setup i was going to start out with http://www.redbrick.dcu.ie/~mcbain/question.jpg so after the math of subtituting the ray equation for the sphere equation, and having your ray direction as a unit vector. I get the roots to be. a = 1 ; b = 2(Dotproduct (V,(p0 - s0)) c = Magnitude(p0 - s0) squared - radius squared. for B I get -4 and C = 7 so b^2 = 16 and 4*c = 28 b^2- 4ac = -12 which cannot be. the ray definatly intersect so im confused as to where im going wrong in the math !!!. heres my workings b = 2( 0.5(2-4) + 0.5(1-3)) = -4 c = ( (2-4)^2 + (1-3)^2)^1/2 - 1^2 = 7 It has to be somehting silly that im missing !!!!

##### Share on other sites
Check Gamasutra for that.

try this

Edit: I knew I will mess up the tags.

or even check this post.

[edited by - OmniBrain on July 18, 2002 2:55:15 AM]

##### Share on other sites
Its not the theory im having problems with its
my working out of the math.

Im fairly sure that the way im going about it
is right, but somewhere in my math (hopefully
someone will show me) im cocking up.

##### Share on other sites
quote:
Original post by SCRUB
...and having your ray direction as a unit vector...

b = 2( 0.5(2-4) + 0.5(1-3)) = -4
c = ( (2-4)^2 + (1-3)^2)^1/2 - 1^2 = 7

Here you haven''t normalized v. If you replace the 0.5s with "root 2 over 2" - I don''t know of a better way to put that - you should get the right answer (well, it works for me). I get b to be -4*(root 2). I hope that relieves some frustration,

Miles

##### Share on other sites
thats the ticket ,jasus , thanks very much I was going out of my nut there.

mucho grascious senoir Miles

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 101
• 11
• ### Forum Statistics

• Total Topics
632975
• Total Posts
3009666
• ### Who's Online (See full list)

There are no registered users currently online

×