Difference between revisions of "LlVecMag"

From Second Life Wiki
Jump to navigation Jump to search
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(18 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{lowercase|llVecMag}}
{{LSL_Function
__NOTOC__
|func=llVecMag
 
|func_id=12|func_sleep=0.0|func_energy=10.0
{| width="100%"
|func_footnote
|-
|p1_type=vector|p1_name=vec|p1_desc
|<div id="box">
|return_type=float
== [[LSL_Type_float|float]] llVecMag( [[LSL_Type_vector|vector]] vec); ==
|return_text=that is the magnitude of the vector (the undirected non-negative distance from {{LSLP|vec}} to {{LSL VR|0.0|0.0|0.0}}).
<div style="padding: 0.5em">
|spec
* vec - Any valid vector value
|caveats
</div>
|examples=
</div>
<source lang="lsl2">
|-
|
<div id="box">
 
== Specification ==
<div style="padding: 0.5em">
Returns the magnitude of vec
{|  
|-
| [[LSL_Energy|Energy]]:
| 10.0  
|-
| [[LSL_Sleep|Sleep]]:
| 0.0  
|-
| [[LSL_Function_ID|Function ID]]:
| 12
|}
</div>
</div>
|-
|
<div id="box">
 
== Caveats ==
<div style="padding: 0.5em">
</div>
</div>
 
|-
|
<div id="box">
== Examples ==
<div style="padding: 0.5em">
<lsl>
default {
default {
     state_entry()
     state_entry()
     {
     {
         vector input = <1.0,2.0,3.0>;
         vector input = <1.0,2.0,3.0>;
         llSay(0,"The magnitude of "+(string)input+" is: "+(string)llVecMag(input) );
         llSay(0,"The magnitude of "+(string)input+" is "+(string)llVecMag(input) + ".");
     }
     }
}
}
</lsl>
</source>
</div>
|helpers
</div>
|also_functions=
|-
{{LSL DefineRow||[[llVecNorm]]|The vector normal}}
|
{{LSL DefineRow||[[llVecDist]]|The distance between two vectors}}
<div id="box">
|also_events
 
|also_tests
== Helper Functions ==
|also_articles
<div style="padding: 0.5em">
|notes=
<lsl>
* Mathematically the formula for vector magnitude is
</lsl>
**  <code>[[llSqrt]](vec.x * vec.x + vec.y * vec.y + vec.z * vec.z)</code>
</div>
* Knowing this, there are ways to circumvent llVecMag for more efficient code.
</div>
** vec*vec < 16.0 is over twice as fast as llVecMag(vec) < 4.0.
|-
** vec*vec < (dist*dist) is about twice as fast as llVecMag(vec) < dist.
|
** This can work in many other ways, too, with other comparisons.
<div id="box">
|permission
== See Also ==
|negative_index
<div style="padding: 0.5em">
|cat1=Math/3D
</div>
|cat2=Vector
</div>
|cat3
|-
|cat4
|
}}
<div id="box">
== Notes ==
<div style="padding: 0.5em">
</div>
</div>
|}
 
[[Category:LSL_Functions]]
[[Category:LSL_Math]]

Latest revision as of 12:00, 22 January 2015

Summary

Function: float llVecMag( vector vec );

Returns a float that is the magnitude of the vector (the undirected non-negative distance from vec to <0.0, 0.0, 0.0>).

• vector vec

Examples

default {
    state_entry()
    {
        vector input = <1.0,2.0,3.0>;
        llSay(0,"The magnitude of "+(string)input+" is "+(string)llVecMag(input) + ".");
    }
}

Notes

  • Mathematically the formula for vector magnitude is
    • llSqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z)
  • Knowing this, there are ways to circumvent llVecMag for more efficient code.
    • vec*vec < 16.0 is over twice as fast as llVecMag(vec) < 4.0.
    • vec*vec < (dist*dist) is about twice as fast as llVecMag(vec) < dist.
    • This can work in many other ways, too, with other comparisons.

See Also

Functions

•  llVecNorm The vector normal
•  llVecDist The distance between two vectors

Deep Notes

Search JIRA for related Issues

Signature

function float llVecMag( vector vec );