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

LSL Wiki : llCos

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawling22.us.archive.org
float llCos(float theta)

Returns the cosine of theta radians.

Given a point on a circumference, it is the horizontal distance from the center, measured in radians.

____
|    \
|     B
|    /|\
|   / | \
|  /  |  \
| /   |   |
A/____C___|D
not a good circle, but measures the distance AC where DB is the number of radians (usually between 0 and TWO_PI) you must go around the circumference.


Radians Angle Cosine
0 0 1
0.392699 22.5 0.923880
0.785398 45 0.707107
1.178097 67.5 0.382683
1.570796 90 0
1.963495 112.5 -0.382684
2.356194 135 -0.707107
2.748893 157.5 -0.923880
3.141593 180 -1
3.534292 202.5 -0.923880
3.926991 225 -0.707107
4.319690 247.5 -0.382684
4.712389 270 0
5.105088 292.5 0.382684
5.497787 315 0.707107
5.890487 337.5 0.923880

The following will rez 16 objects around the object containing the script in a circle. It will use the first object in its inventory as the object to rez.
default
{
    state_entry()
    {
        // name of first object in inventory
        string name = llGetInventoryName(INVENTORY_OBJECT, 0);

        // number of objects to rez
        float count = 16;
        
        // size of circle from center to the edge
        float radius = 5.0;
        
        // distance in radians between each object
        float step = (1.0 / count) * TWO_PI;

        // position on circumference to place object
        float radians; 
        
        // move along circumference
        for(radians = 0.0; radians < TWO_PI; radians += step)
        {
            // get x/y position of circumference
            float x = llCos(radians) * radius;
            float y = llSin(radians) * radius;
            
            // translate relative to objects current position
            vector pos = llGetPos();
            pos.x += x;
            pos.y += y;

            // rez the object
            llRezObject(name, pos, ZERO_VECTOR, ZERO_ROTATION, 0);
        }
    }
}

Compare with llAcos.


Functions | Math
Comments [Hide comments/form]
Attach a comment to this page: