Don't click here unless you want to be banned.

LSL Wiki : llVecDist

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
float llVecDist(vector v1, vector v2)

This function returns the distance between two positional vectors. Here's a table of examples:

v1v2 return value
<0,0,0><1,0,0>1
<0,0,0><0,0,-10>10
<10,0,10><10,0,0>10
<20,0,19><20,0,0>19

The equation for finding vector distance with components is sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2).
or llVecMag(v1 - v2);

//definition
vector VecNorm(vector v) {
    return (v / VecMag(v));
}

float VecMag(vector v) {
    return llSqrt(v.x*v.x + v.y*v.y + v.z*v.z);
}

float VecDist(vector a, vector b) {
    return VecMag(a - b);
}

Compare with llVecMag, and llVecNorm.


This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions / Vectors
Comments [Hide comments/form]
A minor nitpick, it isnt necessary to take the absolute values of those squares.
For all x, y where x,y are elements of the set of reals, (x-y)^2 = abs(x-y)^2
This is nothing more than the general euclidean distance formula in 3-space.
-- FateKnox (2004-04-09 04:39:54)
Your right, squaring a number returns the same result as squaring the opposite (negative of) the number. I *hope* LL didn't use an abs() call, would be a waste of clock cycles ^_^
-- ChristopherOmega (2004-04-21 12:07:21)
Attach a comment to this page: