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

LSL Wiki : llVecNorm

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
vector llVecNorm(vector v)

This function returns the normalized (a.k.a. unit) vector representing v. This vector can be multiplied (scalar) by llVecMag(v) to get v again. Since vectors are used to represent direction as well as location, this function returns the 'simplest form' of the vector, otherwise known as the direction of the vector. If you pass a ZERO_VECTOR (<0,0,0>) to this function, it will return ZERO_VECTOR.

Oversimplification starting point: This reduces the vector to "one". In SL the unit of measure is a meter, so it is somewhat useful to think of this as, instead of a direction pointing 20m to a place, how about reducing it to 1m, but still pointing in the same direction. <0,0,2> (2m up) becomes <0,0,1>. Or, on the complex side: <-1.37821, -0.85432, 2.75875> becomes <-0.43069, -0.26698, 0.86211>.

//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 llVecDist, and llVecMag.


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

Functions | Vector
Comments [Hide comments/form]