VS:Norm: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (1 revision)
(add example, comment about need of 3-dimensional var)
 
Line 33: Line 33:
<return>
<return>
A REAL value which is the length of the vector.</return>
A REAL value which is the length of the vector.</return>
-----------------------------------------------------------------------------------------------------------
<remark>
([[User:CBM-c-|_c_]], 2022.01.20) In Python the vector used as parameter MUST be 3-dimensional, or it will return gibberish. This doesn't matter in Pascal.
</remark>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<sample>
<sample>
==== VectorScript ====
==== VectorScript ====
<code lang="pas">
<code lang="pas">
PROCEDURE Example;
PROCEDURE Example;
VAR
VAR
vec :VECTOR;
    vec :VECTOR;
BEGIN
BEGIN
vec.x := 1;
    vec.x := 1;
vec.y := 1.732050807;
    vec.y := 1.732050807;
Message(Norm(vec));
    Message(Norm(vec));
END;
END;
RUN(Example);</code>
RUN(Example);
 
PROCEDURE Example2;
VAR
    v1, v2 : VECTOR;
BEGIN
    v1.x := 12; v1.y := 1;
    v2.x := 3; v2.y := 15;
    Message( Norm(v1-v2) );
END;
Run(Example2);
</code>
 
==== Python ====
==== Python ====
<code lang="py">
<code lang="py">
 
v1 = (12, 1, 0) # 3-dimensional tuple
v2 = (3, 15, 0)
vs.Message( str(vs.Norm( (v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]) )) )
</code>
</code>
</sample>
</sample>

Latest revision as of 06:28, 20 January 2022

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Returns the length, or magnitude, of the specified vector.

FUNCTION Norm(
Vec :VECTOR) : REAL;
def vs.Norm(Vec):
    return REAL

Parameters

Vec VECTOR Vector to be measured.

Return Value

A REAL value which is the length of the vector.

Remarks

(_c_, 2022.01.20) In Python the vector used as parameter MUST be 3-dimensional, or it will return gibberish. This doesn't matter in Pascal.

Example

VectorScript

PROCEDURE Example;
VAR
    vec :VECTOR;
BEGIN
    vec.x := 1;
    vec.y := 1.732050807;
    Message(Norm(vec));
END;
RUN(Example);

PROCEDURE Example2;
VAR
    v1, v2 : VECTOR;
BEGIN
    v1.x := 12; v1.y := 1;
    v2.x := 3; v2.y := 15;
    Message( Norm(v1-v2) );
END;
Run(Example2);

Python

v1 = (12, 1, 0) # 3-dimensional tuple
v2 = (3, 15, 0)
vs.Message( str(vs.Norm( (v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]) )) )

Version

Availability: from All Versions

See Also

VS Functions:

VS:Distance

VS Functions: [[VS:Distance]]