Beispiel #1
0
def rotation_matrix_between_vectors(from_vec, to_vec):
    """Returns a rotation matrix to rotate from 3d vector "from_vec" to 3d vector "to_vec"."""
    a, b = (trans.unit_vector(vec) for vec in (from_vec, to_vec))
    v = np.cross(a, b)
    cos = np.dot(a, b)
    if cos == -1.:
        raise ValueError("Orientation in complete opposite direction")
    v_cpm = cross_product_matrix(v)
    rot_mat = np.identity(3) + v_cpm + np.dot(v_cpm, v_cpm) * (1. / 1. + cos)
    return rot_mat
Beispiel #2
0
def rotation_matrix_between_vectors(from_vec, to_vec):
    """
    Returns a rotation matrix to rotate from 3d vector "from_vec" to 3d vector "to_vec".
    Equation from https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d
    """
    a, b = (trans.unit_vector(vec) for vec in (from_vec, to_vec))

    v = np.cross(a, b)
    cos = np.dot(a, b)
    if cos == -1.:
        raise ValueError("Orientation in complete opposite direction")
    v_cpm = cross_product_matrix(v)
    rot_mat = np.identity(3) + v_cpm + np.dot(v_cpm, v_cpm) * (1. / 1. + cos)
    return rot_mat
Beispiel #3
0
 def orientation0(self, vector):
     if len(vector) != 3:
         raise ValueError("Orientation vector should be an xyz vector.")
     self._orientation0 = trans.unit_vector(vector)
Beispiel #4
0
 def orientation0(self, vector):
     assert len(vector) == 3
     self._orientation0 = trans.unit_vector(vector)