Original Post
I'm trying to calculate if a vector, at any point, intersects with a circle. I've looked over the many forum posts on the matter and have attempted to utilize the information there. What I've gotten however is something that works very irraticaly. Here is my code - Ok, some explaination - I am using DirectX 9 (which isn't important), but the call D3DXVec3Dot retrieves the dot product of two vectors and the call D3DXVec3Length retrieves the length of the vector. Do I perhaps need to normalize either or both of the two vectors I use to calculate the dot product? I'm also simply assuming that the way vecClosestPoint is being caluclated is correct. I don't understand the maths behind that, if someone could explain how times-ing the direction vector with the dot product and adding that onto the start position gets you the closest point on the vector to the circle, I would be greatly appreciative. Any help would be great. Cheers in advance.
vecToPrey = EndObject->vecPosition - StartObject->vecPosition;
vecToCircle = CircleObject->vecPosition - StartObject->vecPosition;
fDotResult = D3DXVec3Dot(&vecToCircle, &vecToPrey);
vecClosestPoint = StartObject->vecPosition + (vecToPrey * fDotResult);
fDistanceTo = D3DXVec3Length(&(vecClosestPoint - CircleObject->vecPosition));
if (fDistanceTo <= CircleRadius)
{
// then the vector intersects with the circle
}