VS:Perp: Difference between revisions
m (1 revision) |
(add examples) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 35: | Line 35: | ||
----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ||
<remark> | <remark> | ||
([[User: | ([[User:CBM-c-|_c_]], 2022.01.19) In VS Python the tuple returned is always 3-dimensional, but the third value is always zero (see comment below for VS Pascal). So this is a 2D only routine. | ||
([[User:CBM-c-| _c_]], 2011.01.25) The z-value of the vector returned by Perp is always zero. If your source vector has z<>0 the resulting vector might not be what you expect, because of the source vector's angle. | |||
</remark> | </remark> | ||
----------------------------------------------------------------------------------------------------------- | |||
<sample> | |||
==== VectorScript ==== | |||
<code lang="pas"> | |||
PROCEDURE Example; | |||
VAR | |||
v1, v2 : VECTOR; | |||
BEGIN | |||
v1.x := 12; v1.y := 1; | |||
v2.x := 3; v2.y := 15; | |||
Message( Perp(v1-v2) ); | |||
END; | |||
Run(Example); | |||
</code> | |||
==== Python ==== | |||
<code lang="py"> | |||
v1 = (12, 1, 0) # 3-dimensional tuple. Perp accepts also a 2-dimensional tuple | |||
v2 = (3, 15, 0) | |||
vs.Message( str(vs.Perp (v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]) )) ) | |||
</code> | |||
</sample> | |||
----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
Latest revision as of 06:41, 20 January 2022
.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix
Description
Returns a vector which is perpendicular to the specified vector. The resultant vector will have the same magnitude as the source vector, and their scalar product will be zero. The direction of the return vector will equal Vec2Ang(Vec) - 90.
FUNCTION Perp(
Vec :VECTOR) : VECTOR;
def vs.Perp(Vec): return VECTOR
Parameters
Vec VECTOR Source vector.
Return Value
Remarks
(_c_, 2022.01.19) In VS Python the tuple returned is always 3-dimensional, but the third value is always zero (see comment below for VS Pascal). So this is a 2D only routine.
( _c_, 2011.01.25) The z-value of the vector returned by Perp is always zero. If your source vector has z<>0 the resulting vector might not be what you expect, because of the source vector's angle.
Example
VectorScript
PROCEDURE Example; VAR v1, v2 : VECTOR; BEGIN v1.x := 12; v1.y := 1; v2.x := 3; v2.y := 15; Message( Perp(v1-v2) ); END; Run(Example);
Python
v1 = (12, 1, 0) # 3-dimensional tuple. Perp accepts also a 2-dimensional tuple v2 = (3, 15, 0) vs.Message( str(vs.Perp (v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]) )) )
Version
Availability: from All Versions