ray/sphere intersection

Started by
3 comments, last by SCRUB 21 years, 9 months ago
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 !!!!
LE SCRUB
Advertisement
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]
-----The scheduled downtime is omitted cause of technical problems.
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.
LE SCRUB
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

thats the ticket ,jasus , thanks very much I was going out of my nut there.

mucho grascious senoir Miles
LE SCRUB

This topic is closed to new replies.

Advertisement