Jump to content
  • Advertisement
Sign in to follow this  
thyrgle

I need help understanding circle line collision detection.

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

So I am trying to modify the following code taken from here: http://stackoverflow.com/questions/1073336/circle-line-collision-detection (it's the accepted answer) and manipulated it to work with my code. Here is the code:

[source lang = "c"]
float a = d.Dot( d ) ;
float b = 2*f.Dot( d ) ;
float c = f.Dot( f ) - r*r ;

float discriminant = b*b-4*a*c;
if( discriminant < 0 )
{
// no intersection
}
else
{
// ray didn't totally miss sphere,
// so there is a solution to
// the equation.


discriminant = sqrt( discriminant );
float t1 = (-b + discriminant)/(2*a);
float t2 = (-b - discriminant)/(2*a);

if( t1 >= 0 && t1 <= 1 )
{
// solution on is ON THE RAY.
}
else
{
// solution "out of range" of ray
}

// use t2 for second point
}



Since I don't need to worry about anything except whether the ray is intersecting the circle I have reduced it to this:

[source lang = "c"]
float a = d.Dot( d ) ;
float b = 2*f.Dot( d ) ;
float c = f.Dot( f ) - r*r ;

float discriminant = b*b-4*a*c;
if( discriminant < 0 )
{
// no intersection
}
else
{
//it did intersect.
}



But, I am confused on what the Dot( d ). Can anyone help clarify that for me?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by thyrgle
What is the vector dot product?
Just Google/search for 'dot product' or 'vector dot product'.

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.

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!