Search code examples
pythonpython-3.xvectorcompasscross-product

Given two vectors, use the cross product to create a set of three orthonormal vectors


Can anyone help me with this:

Given two vectors, use the cross product to create a set of three orthonormal vectors:

from compas.geometry import cross_vectors
from compas.geometry import angle_vectors
import math as m

v1 = [1,2,3]
v2 = [4,5,6]

Replace... and fill in there:

x1 = #...
x2 = #...
x3 = #...
print(x1)
print(x2)
print(x3)
print(m.degrees(angle_vectors(x1, x2)))
print(m.degrees(angle_vectors(x1, x3)))
print(m.degrees(angle_vectors(x2, x3)))

Solution

  • Given A and B, two independent vectors, a set of 3 orthogonal vectors can be obtained like this:

    C = A x B
    D = A x C

    A, C, D are orthogonal and span the 3D space

    Normalize if you want an orthonormal:

    A/|A|, C/|C|, D/|D|

    I'll let you sort the right and left hand chirality.