line to line distance

Started by
14 comments, last by miles vignol 22 years, 4 months ago
quote:Original post by Timkin
Oluseyi, you should defintely start a new thread to discuss this idea as it sounds like it would make for a great discussion! I''d really like to hear what others have done in this situation too.

Tomorrow. Need sleep now, plus have to finish my term project which is due in about 12 hours... (my fault; I went all out with 2 days to go).

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
Advertisement
LilBudyWizer:

You say,

Now the derivative of d2(t), call it dp2(t), is dp2(t)=dv*dv*2*t+2*dp*dv.


This stuff is good and I see where you are comming from (and going to) but I can''t see where you get the above derivative dp2(t) from. Any expansion would be appreciated.

henry
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
Ok, thanks to another post "Vector Maths" i''ve got it now so please ignore my last post.
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
LilBudy - I think I undersand your solution. I''m assuming that in your final solution for ''t'' you''re using ''*'' to denote a dot product as was the case earlier. I''ll have to see how it breaks down. Seems a lot simpler, but it might just be that there''s additional math being done to get there, considering the solution I derived bears a certain similarity... if (dv*dv==0) then the lines are parellel, yes?

No, it calculates the point where they are closest, not intersection. Two particles travelling on parallel paths at differant speeds still have a time at which they are closest. Also two particles travelling on non-parallel paths do not necessarily ever collide. Their paths cross, but that doesn''t mean both are at the point of intersection at the same time. As an example when you drive down the road your path intersects the paths of countless other cars, but hopefully you are not colliding with any of them. Those other cars were there yesterday, earlier today, last year, ten years ago, will be there tomorrow. To collide with them they have to be there at the same time you are. Also your car is not a point so you can collide even if the centers of your cars are not in the same place at the same time.

The assumption was that you were not going to do pixel perfect collisions. Rather if they are within a certain distance at the time they are closest then you say they collided. After you find the time they are closest you have to calculate sqrt(d2(t)) to find the actual distance between them. If it is less than some amount then the collided. If you want pixel perfect collisions then you have to actually solve d2(t)=(r1+r2)^2 where r1 and r2 is the radius of a bounding circle. The roots then give you the earliest/latest time a collision can occur. Assuming the sprite is any random shape you have to then step from the earliest to latest time and check for overlap of the sprites at each step. The step size would be the largest time interval that results in the fastest moving object moving a distance of one pixel. Rounding may still cause you to miss a collision but by no more than one pixel. Since this is all done between frames the user might suspect, but they will never prove it.

As for the actual derivation of the formula for the derivative it came from actually calculating the derivative of d2(t) and then reducing it to a simple formula. I use MathCAD so it is easiest just to carry everything through to the end. rab(t) is actually dp+dv*t. That makes d2(t)=dp*dp+2*dv*dp*t+dv*dv*t^2 in terms of dot products. Dot products work pretty much the same as coefficients a in scalar equation. Well, maybe exactly. So (a+b)*(c+d)=a*c+a*d+b*c+b*d except here it is (a+b*t)^2. As for whether it is a dot product or multiplication it depends. If it is two vectors, i.e. dv or dp, it is a dot product. If it is a vector and a scalar then it is scaling the vector. If it is two scalars then it is just normal multiplication. Specifically 2*dp*dv*t is the dot product of dp and dv scaled by the scalar product of 2 and t.
Keys to success: Ability, ambition and opportunity.
Uhh... yeah, we''re on the same page. I started multiplying out your solution and it quickly becomes the one that I derived, tho in a more direct route. The only time it fails is when (dv*dv)==0 which only happens when the objects are moving in the same direction (lines parallel) at the same speed (equal length). Even if they''re parallel, there will be a time when the points are closest so long as they''re not travelling at the same speed. If they''re also moving at the same speed (va == vb) then I can use any value for t at it will yield no difference in the distance equation.

This topic is closed to new replies.

Advertisement