Difference between revisions of "LlGetGeometricCenter"

From Second Life Wiki
Jump to navigation Jump to search
m (+Note)
m
 
(8 intermediate revisions by 5 users not shown)
Line 6: Line 6:
|Return_text=that is the geometric center of the object [[Viewer_coordinate_frames#Local|relative]] to the root prim.
|Return_text=that is the geometric center of the object [[Viewer_coordinate_frames#Local|relative]] to the root prim.
|spec
|spec
|caveats=This is currently (as of 2 December 2010) different from "center" in viewer's build tools and what [[llRezObject]] considers as "center" of linkset.
|caveats=The "geometric center" is different from the "center" in viewer's build tools and also different from what [[llRezObject]] considers to be the "center" of a linkset.
|constants
|constants
|examples
|examples=<source lang="lsl2">default
{
    touch_start(integer total_number)
    {
        llOwnerSay("Geometric center of the object relative to the root prim: " + (string)llGetGeometricCenter());
    }
}</source>
|helpers
|helpers
|also_functions=
|also_functions=
Line 16: Line 22:
|also_articles
|also_articles
|notes=
|notes=
* Geometric center is the average of all linked prim centers. Mathematically it's the region position of all linked prims in the linkset added together and divided by the number of prims in the linkset.
* The "geometric center" is the average of all linked prim centers. Mathematically, it's the root-relative positions of all linked prims in the linkset added together and divided by the number of prims in the linkset.
|deepnotes=
<source lang="lsl2">vector GetGeometricCenter(){
    vector center = ZERO_VECTOR;
    integer p = llGetNumberOfPrims();
    //since we skip the root prim, we can ignore the single prim case.
    //If we weren't skipping the root, this would be more complicated.
    integer i = 1;
    while(i < p)
        center += llList2Vector(llGetLinkPrimitiveParams(++i, [PRIM_POS_LOCAL]), 0);
    return center / p;
}</source>
|haiku={{Haiku|With each added prim|away shifts our origin|to encompass all.}}
|cat1=Physics
|cat1=Physics
|cat2
|cat2

Latest revision as of 06:10, 12 August 2023

Summary

Function: vector llGetGeometricCenter( );
0.0 Forced Delay
10.0 Energy

Returns the vector that is the geometric center of the object relative to the root prim.

Caveats

The "geometric center" is different from the "center" in viewer's build tools and also different from what llRezObject considers to be the "center" of a linkset.

Examples

default
{
    touch_start(integer total_number)
    {
        llOwnerSay("Geometric center of the object relative to the root prim: " + (string)llGetGeometricCenter());
    }
}

Notes

  • The "geometric center" is the average of all linked prim centers. Mathematically, it's the root-relative positions of all linked prims in the linkset added together and divided by the number of prims in the linkset.

See Also

Functions

•  llGetCenterOfMass

Deep Notes

vector GetGeometricCenter(){
    vector center = ZERO_VECTOR;
    integer p = llGetNumberOfPrims();
    //since we skip the root prim, we can ignore the single prim case.
    //If we weren't skipping the root, this would be more complicated.
    integer i = 1;
    while(i < p)
        center += llList2Vector(llGetLinkPrimitiveParams(++i, [PRIM_POS_LOCAL]), 0);
    return center / p;
}

Signature

function vector llGetGeometricCenter();

Haiku

With each added prim
away shifts our origin
to encompass all.