VS:CrossProduct: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
(add note about returned var dimension)
(add examples)
Line 43: Line 43:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<remark>
([[User:CBM-c-|_c_]], 2022.01.20) The vector returned is always 3-dimensional: Pascal: vector {x, y, z}, Python: tuple (0.0, 0.0, 0.0)
([[User:CBM-c-|_c_]], 2022.01.20) The vector returned is always 3-dimensional: Pascal: vector {x, y, z}, Python: tuple (0.0, 0.0, 0.0).
The two vectors used as parameters MUST be 3-dimensional, or it will return gibberish for the x, y values.


<code lang="py">
# EXAMPLE OF FAULTY USAGE
v1 = (12, 1) # bidimensional
v2 = (3, 15)
vs.Message( str(vs.CrossProduct(v1, v2)) )
# returns gibberish for first two items
</code>


[[User:Ptr|Ptr]] [2021.05.12]:
[[User:Ptr|Ptr]] [2021.05.12]:
Line 57: Line 65:


</remark>
</remark>
-----------------------------------------------------------------------------------------------------------
<sample>
==== VectorScript ====
<code lang=pas>
PROCEDURE TEST;
VAR
    v1, v2 : VECTOR;
BEGIN
    v1.x := 12; v1.y := 1; v1.z := 0;
    v2.x := 3; v2.y := 15; v2.z := 0;
    Message( CrossProduct(v1, v2)); { returns a 3-dimensional VECTOR }
END;
Run(TEST);
</code>
==== Python ====
<code lang="py">
v1 = (12, 1, 0)
v2 = (3, 15, 0)
vs.Message( str(vs.CrossProduct(v1, v2)) ) # returns a 3-dimensional tuple
</code>
</sample>


-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------

Revision as of 05:37, 20 January 2022

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

Description

Returns the cross product of the two specified vectors.

The cross product is also known as the vector product of the two vectors. The result is a vector whose magnitude is equivalent to the product of the magnitudes of the two vectors multiplied by the sine of the smaller angle between the two vectors. The direction of the resultant vector is perpendicular to a plane formed by the two source vectors.

FUNCTION CrossProduct(
v1 :VECTOR;
v2 :VECTOR) : VECTOR;
def vs.CrossProduct(v1, v2):
    return VECTOR

Parameters

v1 VECTOR Source vector 1.
v2 VECTOR Source vector 2.

Return Value

Returns a VECTOR which is the cross product of v1 and v2.

Remarks

(_c_, 2022.01.20) The vector returned is always 3-dimensional: Pascal: vector {x, y, z}, Python: tuple (0.0, 0.0, 0.0).

The two vectors used as parameters MUST be 3-dimensional, or it will return gibberish for the x, y values.

# EXAMPLE OF FAULTY USAGE
v1 = (12, 1) # bidimensional
v2 = (3, 15) 
vs.Message( str(vs.CrossProduct(v1, v2)) ) 
# returns gibberish for first two items

Ptr [2021.05.12]: Since in Python a VECTOR doesn't exist, you need to use tuples instead.

older posts whose author got lost:

This is provided for cross-platform compatibility.

To elaborate a little... The first vector defines the X axis of a new coordinate system; the second vector defines the positive Y direction in that coordinate system. The cross product of those vectors will be in the positive Z direction.

Example

VectorScript

PROCEDURE TEST;
VAR
    v1, v2 : VECTOR;

BEGIN
    v1.x := 12; v1.y := 1; v1.z := 0;
    v2.x := 3; v2.y := 15; v2.z := 0;
    Message( CrossProduct(v1, v2)); { returns a 3-dimensional VECTOR }
END;
Run(TEST);

Python

v1 = (12, 1, 0)
v2 = (3, 15, 0)
vs.Message( str(vs.CrossProduct(v1, v2)) ) # returns a 3-dimensional tuple

Version

Availability: from VectorWorks 8.5