From 478f44692693ff00510b661d533e3f230966c7ad Mon Sep 17 00:00:00 2001 From: "Michele.Maris" <michele.maris@inaf.it> Date: Sat, 5 Aug 2023 21:49:49 +0200 Subject: [PATCH] u --- src/yapsut/geometry.py | 2 + src/yapsut/roto_translation.py | 48 +++++++++++ src/yapsut/vectorized_elemental_rotations.py | 91 ++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 src/yapsut/roto_translation.py create mode 100644 src/yapsut/vectorized_elemental_rotations.py diff --git a/src/yapsut/geometry.py b/src/yapsut/geometry.py index e439d59..af72b34 100644 --- a/src/yapsut/geometry.py +++ b/src/yapsut/geometry.py @@ -1,4 +1,6 @@ import numpy as np +from .roto_translation import transform,roto_trans_matrix +from .vectorized_elemental_rotations import vERotX, vERotY, vERotZ, vAX3D, vAY3D, vAZ3D class ElipsoidTriangulation : """ creates an elipsoid triangulated """ @property diff --git a/src/yapsut/roto_translation.py b/src/yapsut/roto_translation.py new file mode 100644 index 0000000..5726639 --- /dev/null +++ b/src/yapsut/roto_translation.py @@ -0,0 +1,48 @@ +__DESCRIPTION__=""" + +not vectorized rototranslation library + +M.Maris - V0.0 - 2018 May 03 - + + +""" +import numpy as np + + +def transform(point, TransformArray): + """ apply a transformation to a 4d point """ + p = np.array([0,0,0,1]) + for i in range (0,len(point)-1): + p[i] = point[i] + p=np.dot(TransformArray,np.transpose(p)) + for i in range (0,len(point)-1): + point[i]=p[i] + return point + +def roto_trans_matrix(rotation, translation): + """returns a rototranslation matrix + """ + xC, xS = trig(rotation[0]) + yC, yS = trig(rotation[1]) + zC, zS = trig(rotation[2]) + dX = translation[0] + dY = translation[1] + dZ = translation[2] + Translate_matrix = np.array([[1, 0, 0, dX], + [0, 1, 0, dY], + [0, 0, 1, dZ], + [0, 0, 0, 1]]) + Rotate_X_matrix = np.array([[1, 0, 0, 0], + [0, xC, -xS, 0], + [0, xS, xC, 0], + [0, 0, 0, 1]]) + Rotate_Y_matrix = np.array([[yC, 0, yS, 0], + [0, 1, 0, 0], + [-yS, 0, yC, 0], + [0, 0, 0, 1]]) + Rotate_Z_matrix = np.array([[zC, -zS, 0, 0], + [zS, zC, 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1]]) + return np.dot(Rotate_Z_matrix,np.dot(Rotate_Y_matrix,np.dot(Rotate_X_matrix,Translate_matrix))) + diff --git a/src/yapsut/vectorized_elemental_rotations.py b/src/yapsut/vectorized_elemental_rotations.py new file mode 100644 index 0000000..3a4f615 --- /dev/null +++ b/src/yapsut/vectorized_elemental_rotations.py @@ -0,0 +1,91 @@ +__DESCRIPTION__=""" + +vectorized elemental rotations + +M.Maris - V0.0 - 2023 Aug 05 - + + +""" +import numpy as np + +# 3D versors X, Y, Z +vAX3D = np.array([1,0,0]) +vAY3D = np.array([0,1,0]) +vAZ3D = np.array([0,0,1]) + + +def _vectorized_rotation_base_matrix(self,Angle) : + """ +commodity function to define a base for a vectorized rotation matrix, returns the components +I, c, s of a list of elemental 3D rotation matrices with + + I.shape=(N,3,3), + c.shape=N, + s.shape=N. + +with N = 1 is Angle is scalar, otherwise N=len(Angle) + + Parameters + ---------- + :Angle: scalar or array of rotation angle(s) in radiants + """ + _angle=np.array([Angle]) if np.isscalar(Angle) else Angle + c=np.cos(_angle) + s=np.sin(_angle) + I=np.zeros([len(_angle),3,3]) + I[:,0,0]=1 + I[:,1,1]=1 + I[:,2,2]=1 + return I,c,s + +def vERotX(Angle) : + """Vectorized elemental rotations about X axis + + returns a list of elemental 3D rotation matrices with shape (N,3,3) + with N = 1 if Angle is scalar, otherwise N=len(Angle) + + Parameters + ---------- + :Angle: scalar or array of rotation angle(s) in radiants + """ + R,c,s=_vectorized_rotation_base_matrix(Angle) + R[:,1,1]= c + R[:,1,2]=-s + R[:,2,1]= s + R[:,2,2]= c + return R + +def vERotY(Angle) : + """Vectorized elemental rotations about Y axis + + returns a list of elemental 3D rotation matrices with shape (N,3,3) + with N = 1 if Angle is scalar, otherwise N=len(Angle) + + Parameters + ---------- + :Angle: scalar or array of rotation angle(s) in radiants + """ + R,c,s=_vectorized_rotation_base_matrix(Angle) + R[:,0,0]= c + R[:,0,2]= s + R[:,2,0]=-s + R[:,2,2]= c + return R + +def vERotZ(Angle) : + """Vectorized elemental rotations about Z axis + + returns a list of elemental 3D rotation matrices with shape (N,3,3) + with N = 1 if Angle is scalar, otherwise N=len(Angle) + + Parameters + ---------- + :Angle: scalar or array of rotation angle(s) in radiants + """ + R,c,s=_vectorized_rotation_base_matrix(Angle) + R[:,0,0]= c + R[:,0,1]=-s + R[:,1,0]= s + R[:,1,1]= c + return R + -- GitLab