Bosozoku Kato
insurrectionist midget
Join date: 16 Jun 2003
Posts: 452
|
07-06-2005 16:18
I'm mathematically challenged! Need some help on how to calculate a vector that's a given distance between two known vectors.
example: vector vMyPos = llGetPos(); vector vYourpos = <some vector way over there...>
What I need is a formula to find a position in between the 2 known vectors, at a given distance. If you are 50m from me, I want to find the pos that's 13m from my pos, on a direct line to your position.
--Bos
|
Torn Bobbysocks
Registered User
Join date: 6 Jul 2005
Posts: 11
|
07-06-2005 16:25
I found this in another thread, you might find it helpful: // By Chris Omega vector setVectorDistance(vector destination, float distance) { if (llVecDist(llGetPos(), destination) < distance) { return destination; } else { // Argh, we actually have to do math. vector offset = destination - llGetPos(); return llVecNorm(offset) * distance + llGetPos(); } }
Here's something that might help for your problem specificly: vector shortenVector(vector startPoint, vector endPoint, float distance) { vector offset = endPoint - startPoint; return llVecNorm(offset) * distance + startPoint }
|
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
|
07-07-2005 01:10
You don't need trig for that.
There's a quick way to do it - using something similar to how you take an average.
So if you do: (you + me)/2 you get the point halfway between us (the average).
If you want something x metres away from me, in the direction of you, where d is llVecDist(you, me), it is:
(x/d)*me + (1-(x/d))*you
If you stick in x = d/2 (that is you want the midpoint between us) then you'll see that it comes out to be just the average.
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
07-07-2005 02:28
just use vector norm.
me + (llVecNorm(you - me) * desired_distance)
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Bosozoku Kato
insurrectionist midget
Join date: 16 Jun 2003
Posts: 452
|
07-07-2005 03:27
Thanks guys  Will give those samples a run. I really should have paid attention in school... alas, the beach was too close by. --Bos
|