Public Group

# I need help understanding circle line collision detection.

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

## 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 on other sites
It is the vector dot product.

##### Share on other sites
What is the vector dot product?

##### Share on other sites
Quote:
 Original post by thyrgleWhat is the vector dot product?
Just Google/search for 'dot product' or 'vector dot product'.

##### Share on other sites
Ok, thanks everyone it makes sense now. :)

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009837
• ### Who's Online (See full list)

There are no registered users currently online

×