You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.
This is an old revision of the document!
float llCos(float arg)
Return the cosine of the argument. The argument should be an angle in radians.
Angle whose cosine is to be found, in radians.
Cosine of the argument.
float F; F = llCos(1); // Sets F to approx. 0.540302, because that's the cosine of 1 radian. F = llCos(-1); // Sets F to approx. 0.540302 too, //because the cosine of -1 radian equals the cosine of 1 radian. F = llCos(0); // Sets F to 1, because that's the cosine of 0. F = llCos(PI); // Sets F to -1, which is the cosine of PI. F = llCos(1e20); // Sets F to 1e20 because 1e20 is returned unchanged. rotation rot; float a = 30*DEG_TO_RAD; rot = <llSin(a/2), 0, 0, llCos(a/2)>; // Sets rot to a rotation over the X axis by 30° counter-clockwise. rot = <-llSin(a/2), 0, 0, llCos(a/2)>; // Sets rot to a rotation over the X axis by 30° clockwise. rot = <0, llSin(a/2), 0, llCos(a/2)>; // Sets rot to a rotation over the Y axis by 30° counter-clockwise. rot = <0, 0, llSin(a/2), llCos(a/2)>; // Sets rot to a rotation over the Z axis by 30° counter-clockwise.
Note: the last four examples are faster than their equivalents using llEuler2Rot, which are:
rot = llEuler2Rot(<30,0,0>*DEG_TO_RAD); rot = llEuler2Rot(<-30,0,0>*DEG_TO_RAD); rot = llEuler2Rot(<0,30,0>*DEG_TO_RAD); rot = llEuler2Rot(<0,0,30>*DEG_TO_RAD);
llCos is very frequently used together with llSin, as llCos gives the X component and llSin the Y component of a unit vector at the given angle.
default { state_entry() { llOwnerSay("Calculate a vector at an angle. Please say the angle in chat."); llListen(0, "", llGetOwner(), ""); } listen(integer chan, string name, key id, string msg) { float angle = (float)msg * DEG_TO_RAD; llOwnerSay("Input angle: " + msg + "; resulting vector: (" + (string)llCos(angle) + ", " + (string)llSin(angle) + ")"); } }