Difference between revisions of "LlVecMag"

From Second Life Wiki
Jump to: navigation, search
m (LSL llVecMag moved to LlVecMag: removing prefix)
m (Replaced old <LSL> block with <source lang="lsl2">)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
{{LSL_Function
 
{{LSL_Function
 
|func=llVecMag
 
|func=llVecMag
|func_id=12
+
|func_id=12|func_sleep=0.0|func_energy=10.0
|func_sleep=0.0
+
|func_energy=10.0
+
 
|func_footnote
 
|func_footnote
|p1_type=vector
+
|p1_type=vector|p1_name=vec|p1_desc
|p1_name=vec
+
|p1_desc
+
|p2_type|p2_name|p2_desc
+
|p3_type|p3_name|p3_desc
+
|p4_type|p4_name|p4_desc
+
|p5_type|p5_name|p5_desc
+
|p6_type|p6_name|p6_desc
+
|p7_type|p7_name|p7_desc
+
|p8_type|p8_name|p8_desc
+
|p9_type|p9_name|p9_desc
+
|p10_type|p10_name|p10_desc
+
|p11_type|p11_name|p11_desc
+
|p12_type|p12_name|p12_desc
+
 
|return_type=float
 
|return_type=float
|return_text=that is the magnitude of the vector (the distance from '''vec''' to <0.0, 0.0, 0.0>).
+
|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}}).
 
|spec
 
|spec
 
|caveats
 
|caveats
 
|examples=
 
|examples=
<lsl>
+
<source lang="lsl2">
 
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>
 
|helpers
 
|helpers
|also_functions=*{{LSLG|llVecNorm}}
+
|also_functions=
*{{LSLG|llVecDist}}
+
{{LSL DefineRow||[[llVecNorm]]|The vector normal}}
 +
{{LSL DefineRow||[[llVecDist]]|The distance between two vectors}}
 
|also_events
 
|also_events
 
|also_tests
 
|also_tests
 
|also_articles
 
|also_articles
|notes
+
|notes=
 +
* Mathematically the formula for vector magnitude is
 +
**  <code>[[llSqrt]](vec.x * vec.x + vec.y * vec.y + vec.z * vec.z)</code>
 +
* 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.
 
|permission
 
|permission
 
|negative_index
 
|negative_index
 
|cat1=Math/3D
 
|cat1=Math/3D
|cat2
+
|cat2=Vector
 
|cat3
 
|cat3
|cat4=Stub
+
|cat4
 
}}
 
}}

Latest revision as of 11: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 );