VS:UnitVec: Difference between revisions
Jump to navigation
Jump to search
(document: vector in Py 3-dimensional) |
(add comment and examples about 3-dimensional) |
||
Line 29: | Line 29: | ||
</lineList> | </lineList> | ||
</params> | </params> | ||
----------------------------------------------------------------------------------------------------------- | |||
<return> | |||
Returns a VECTOR.</return> | |||
----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ||
<remark> | <remark> | ||
([[User:CBM-c-|_c_]], 2022.01.19) | ([[User:CBM-c-|_c_]], 2022.01.19) The vector returned is always 3-dimensional: Pascal: vector {x, y, z}, Python: tuple (0.0, 0.0, 0.0). | ||
Note: in Python the vector used as parameter MUST be 3-dimensional, or UnitVec will return gibberish. This doesn't matter in Pascal. | |||
</remark> | </remark> | ||
----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ||
< | <sample> | ||
==== VectorScript ==== | |||
<code lang=pas> | |||
PROCEDURE TEST; | |||
VAR | |||
v1, v2 : VECTOR; | |||
BEGIN | |||
v1.x := 12; v1.y := 1; v1.z := 0; { can be a 3-dimensional Vector, doesn't need to, though } | |||
v2.x := 3; v2.y := 15; v2.z := 0; | |||
Message( UnitVec(v1 - v2)); { returns a 3-dimensional Vector } | |||
END; | |||
Run(TEST); | |||
</code> | |||
==== Python ==== | |||
<code lang="py"> | |||
v1 = (12, 1, 0) # must be a 3-dimensional tuple, or you'll get gibberish in the returned vector | |||
v2 = (3, 15, 0) | |||
vs.Message( str(vs.UnitVec( (v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]) )) ) {#returns a 3-dimensional tuple | |||
</code> | |||
</sample> | |||
----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
Revision as of 06:50, 20 January 2022
.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix
Description
Returns the standard unit vector of the specified vector.
FUNCTION UnitVec(
Vect :VECTOR) : VECTOR;
def vs.UnitVec(Vect): return VECTOR
Parameters
Vect VECTOR Source vector.
Return Value
Remarks
(_c_, 2022.01.19) The vector returned is always 3-dimensional: Pascal: vector {x, y, z}, Python: tuple (0.0, 0.0, 0.0).
Note: in Python the vector used as parameter MUST be 3-dimensional, or UnitVec will return gibberish. This doesn't matter in Pascal.
Example
VectorScript
PROCEDURE TEST; VAR v1, v2 : VECTOR; BEGIN v1.x := 12; v1.y := 1; v1.z := 0; { can be a 3-dimensional Vector, doesn't need to, though } v2.x := 3; v2.y := 15; v2.z := 0; Message( UnitVec(v1 - v2)); { returns a 3-dimensional Vector } END; Run(TEST);
Python
v1 = (12, 1, 0) # must be a 3-dimensional tuple, or you'll get gibberish in the returned vector v2 = (3, 15, 0) vs.Message( str(vs.UnitVec( (v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]) )) ) {#returns a 3-dimensional tuple
Version
Availability: from All Versions