How can you calculate the cross product of two vectors?


In ANSYS, Release 10.0, you can use *VOPER to calculate the cross product of two vectors. The i,j,k values for each vector are stored in rows of an array. The i,j,k values of the result vector is then stored in another array. See the example below.

! Cross product (a.b) of 2 vectors
! axb = (ajbk-akbj)i + (akbi-aibk)j + (aibj-ajbi)k

! This test case has 4 vectors
! Vector 1 = 1i + 1j + 1k
! Vector 2 = 2i + 2j + 2k
! Vector 3 = 1i + 2j + 3k
! Vector 4 = 4i + 5j + 6k
! Vector 1 is stored in row 1 of a1
! Vector 2 is stored in row 2 of a1
! Vector 3 is stored in row 1 of a2
! Vector 4 is stored in row 2 of a2

*dim,a1,,2,3
*dim,a2,,2,3
*dim,a3,,2,3
*dim,a4,,2,3

a1(1,1) = 1,2
a1(1,2) = 1,2
a1(1,3) = 1,2
a2(1,1) = 1,4
a2(1,2) = 2,5
a2(1,3) = 3,6

! Take the cross product of vectors 1 and 3
! and store the results in row 1,
! columns 1,2,3 of a3.
! Also, take the cross product of vectors 2
! and 4, and store the results in row 2
! columns 1,2,3 of a3.
/com,
/com, V1xV3 = (1*3-1*2)i + (1*1-1*3)j + (1*2-1*1)k
/com, V1xV3 = 1, -2, 1
/com,
/com, V2xV4 = (2*6-2*5)i + (2*4-2*6)j + (2*5-2*4)k
/com, V2xV4 = 2, -4, 2

*voper,a3(1),a1(1),cross,a2(1)
*status,a3,1,1,1,3 ! V1xV3
*status,a3,2,2,1,3 ! V2xV4

! Take the dot product of vectors 2 and 4
! and store the result in a4(2,1).
/com,
/com, V2xV4 = (2*6-2*5)i + (2*4-2*6)j + (2*5-2*4)k
/com, V2xV4 = 2, -4, 2
/com,
*voper,a4(2),a1(2),cross,a2(2)
*status,a4,2,2,1,3





Show Form
No comments yet. Be the first to add a comment!