|
Kaiyos Czukor
Registered User
Join date: 23 Jun 2004
Posts: 9
|
10-27-2005 12:48
Okay, given position vector P of an object, and a velocity vector V of another object, how would I go about telling if the two objects are on a collision course?
Right now, I'm guessing that if I normalize both vectors and compare them, the closer the two unit vectors are, the close one object will come to hitting the other.
I haven't read up on physics in a loong time. Am I right now this?
|
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
10-27-2005 13:22
Ok, it's been a while since I did basic collision physics but I'll take take a swing at it. And if someone comes along and provides correct or more correct information than myself, *thank you*.
Ok, I think it goes like this: P1 would be the first Position vector. P2 would be the second Position vector.
projected vector x value = ( (P1.x*P2.x + P1.y*P2.y) / (P2.x*P2.x + P2.y*P2.y) ) * P2.x; projected vector y value = ( (P1.x*P2.x + P1.y*P2.y) / (P2.x*P2.x + P2.y*P2.y) ) * P2.y; And, I think Z is done differently so I'm not going to hazard a guess... sorry.
But I do seem to remember that if Position 2 is a unit vector (P2.x*P2.x + P2.y*P2.y) = 1, than you need to reduce the formula to: projected vector x value = (P1.x*P2.x + P1.y*P2.y) * P2.x; projected vector y value = (P1.x*P2.x + P1.y*P2.y) * P2.y;
To determine a collision, this doesn't take into acct something moving away from it... I'll leave that up to you, you would check the position twice. If both times the projected x & y are the same as the llGetPos x and y, then you more than likely have a collision.
Geez, I hope that's not completely wrong and I hope it helps you some. If anyone can answer this better, I'm sure all of us would love to hear it.... and it'll save me from looking in my closet for my physics books! Good Luck!
|
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
10-27-2005 13:28
From: Cid Jacobs To determine a collision, this doesn't take into acct something moving away from it... I'll leave that up to you, Duh! Just occurred to my slow moving brain today... llVectDist is perfect for that. 
|
|
Kaiyos Czukor
Registered User
Join date: 23 Jun 2004
Posts: 9
|
10-27-2005 14:09
I think I might have it now. Subtract the position vectors of both objects. That'll give you the vector for the path straight from one object to the other. Normalize it, normalize the velocity vector, and compare. It seems pretty simple now. That is, unless I've made some horrible mistake in my understanding of physical reality. 
|
|
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
|
10-27-2005 14:43
From: Kaiyos Czukor I think I might have it now. Subtract the position vectors of both objects. That'll give you the vector for the path straight from one object to the other. Normalize it, normalize the velocity vector, and compare. It seems pretty simple now. That is, unless I've made some horrible mistake in my understanding of physical reality.  You know, some day I'll learn to try and answer these physics questions with built in functions.... default { state_entry() { llSensorRepeat... }
sensor(integer total_number) { if(llVecNorm(llGetPos() - llDetectedPos(0)) == llVecNorm(llDetectedVel(0))) { llSay(0,"Run for your life!"); } } }
|