# -*- coding: utf-8 -*-
import numpy as np
import copy
import sys
import pdb
from math import *
from inPy.Classes import *
from inPy.inPy_Constants import *
##################################
# General functions #
##################################
[docs]def RotVect_to_RotMat(Vect):
"""
input: rotation vector of shape 1x3
output: rotation matrix 3x3
"""
xAngle = Vect[0]
yAngle = Vect[1]
zAngle = Vect[2]
# rotation around x
xRot_Mat = np.array([[1,0,0],[0,np.cos(xAngle),-np.sin(xAngle)],[0,np.sin(xAngle),np.cos(xAngle)]])
# rotation around y
yRot_Mat = np.array([[np.cos(yAngle),0,np.sin(yAngle)],[0,1,0],[-np.sin(yAngle),0,np.cos(yAngle)]])
# rotation around z
zRot_Mat = np.array([[np.cos(zAngle),-np.sin(zAngle),0],[np.sin(zAngle),np.cos(zAngle),0],[0,0,1]])
# matrix multplication
RotMat = np.dot(np.dot(xRot_Mat,yRot_Mat),zRot_Mat)
return RotMat
[docs]def Get_angle(Vector1,Vector2,Rad_or_Deg = "Rad"):
"""
This function returns the angle (rad) between two vectors
input: Vector1 (numpy array or list) and Vector2 (numpy array or list)
output: angle between the two (float)
Optional parameter: Rad_or_Deg, default to Rad, defines if the angle should be returned
in radians or degrees
"""
if Rad_or_Deg == "Deg":
Factor = 180/PI
elif Rad_or_Deg == "Rad":
Factor = 1
return Factor*acos(np.dot(Vector1,Vector2)/(np.linalg.norm(Vector1)*np.linalg.norm(Vector2)))