Difference between revisions of "LlRotBetween"

From Second Life Wiki
Jump to navigation Jump to search
(*sigh* honest mistakes are honest, like typos and posting the wrong script version, but being outright wrong is another issue.)
Line 5: Line 5:
|func_footnote
|func_footnote
|func_desc
|func_desc
|return_text=that is the rotation between a vector pointing to '''start''' and one pointing to '''end'''
|return_text=that is the rotation between the direction '''start''' and the direction '''end'''
|spec='''start''' and '''end''' are 2 positions which are relative to the origin of the prim the script is in. Be sure these are relative positions, not world positions, so if you have world positions, subtract the prim origin first.<br><br>
|spec='''start''' and '''end''' are directions and are relative to the origin <0.0, 0.0, 0.0>. If you have world positions you will want to make them local to a position, subtract that position from the vectors.
Also remember that these are positions that define directions, so for example if you want to find a rotation to get from forward (along the positive X axis) to some point 45 degrees to the right, a possible set of vectors would be <1, 0, 0> and <1,-1,0>. The first defines the forward direction, the second the 45 degrees to the right (remember the right hand rule says +Y is to the left).
|caveats=*<code>start * llRotBetween(start, end) == end</code> is only true if '''start''' and '''end''' have the same magnitude and neither have a magnitude of zero.
|caveats
|constants
|constants
|examples=llRotBetween (<1, 0, 0>, <0, -1, 0>) will return <0.00000, 0.00000, -1.57080> (-1.57080 is 45 degrees in radians)
|examples=
<pre>llRotBetween(<1.0, 0.0, 0.0>, <0.0, -1.0, 0.0>)
// will return <0.00000, 0.00000, -0.70711, 0.70711> (which represents -45 degrees on the z axis)


llRotBetween (<0, 0, 0>, <0, -1, 0>) will return <0.00000, 0.00000, 0.00000> because <0, 0, 0> doesn't define a direction.
llRotBetween(<0.0, 0.0, 0.0>, <0.0, -1.0, 0.0>)
// will return <0.00000, 0.00000, 0.00000, 1.00000> (which represents a zero angle on all axis)
// because <0.0, 0.0, 0.0> does not convey a direction.</pre>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llAngleBetween]]}}
|also_functions={{LSL DefineRow||[[llAngleBetween]]}}
Line 18: Line 21:
|also_events
|also_events
|also_articles
|also_articles
|notes
|notes=
This function adjusts the magnitude of the quaternion so <code>start * llRotBetween(start, end) == end</code> is true as long as neither have a magnitude of zero. They don't have to have the same magnitude.
<pre>
rotation RotBetween(vector start, vector end) //adjusts quaternion magnitude so (start * return == end)
{//Authors note: I have never had a use for this but it's good to know how to do it if I did.
    rotation rot = llRotBetween(start, end);
    if(start)
    {
        if(end)
        {
            float d = llSqrt(llVecMag(end) / llVecMag(start));
            return <rot .x * d, rot .y * d, rot .z * d, rot .s * d>;
        }
    }
    return rot;
}//Strife Onizuka
</pre>
|deprecated
|deprecated
|cat1=Math/3D
|cat1=Math/3D

Revision as of 00:47, 20 September 2007

Summary

Function: rotation llRotBetween( vector start, vector end );

Returns a rotation that is the rotation between the direction start and the direction end

• vector start
• vector end

Specification

start and end are directions and are relative to the origin <0.0, 0.0, 0.0>. If you have world positions you will want to make them local to a position, subtract that position from the vectors.

Caveats

  • start * llRotBetween(start, end) == end is only true if start and end have the same magnitude and neither have a magnitude of zero.
All Issues ~ Search JIRA for related Bugs

Examples

llRotBetween(<1.0, 0.0, 0.0>, <0.0, -1.0, 0.0>)
// will return <0.00000, 0.00000, -0.70711, 0.70711> (which represents -45 degrees on the z axis)

llRotBetween(<0.0, 0.0, 0.0>, <0.0, -1.0, 0.0>)
// will return <0.00000, 0.00000, 0.00000, 1.00000> (which represents a zero angle on all axis)
// because <0.0, 0.0, 0.0> does not convey a direction.

Notes

This function adjusts the magnitude of the quaternion so start * llRotBetween(start, end) == end is true as long as neither have a magnitude of zero. They don't have to have the same magnitude.

rotation RotBetween(vector start, vector end) //adjusts quaternion magnitude so (start * return == end) 
{//Authors note: I have never had a use for this but it's good to know how to do it if I did.
    rotation rot = llRotBetween(start, end);
    if(start)
    {
        if(end)
        {
            float d = llSqrt(llVecMag(end) / llVecMag(start));
            return <rot .x * d, rot .y * d, rot .z * d, rot .s * d>;
        }
    }
    return rot;
}//Strife Onizuka

See Also

Functions

•  llAngleBetween

Deep Notes

Search JIRA for related Issues

Signature

function rotation llRotBetween( vector start, vector end );