33import numpy as np
44
55from sas .sascalc .shape2sas .HelperFunctions import Qsampling , euler_rotation_matrix
6- from sas .sascalc .shape2sas .models import *
7- from sas .sascalc .shape2sas .Typing import *
6+ from sas .sascalc .shape2sas .models import \
7+ Cube , Cuboid , Cylinder , CylinderRing , Disc , DiscRing , Ellipsoid , \
8+ EllipticalCylinder , HollowCube , HollowSphere , Sphere , SuperEllipsoid
9+ from sas .sascalc .shape2sas .Typing import Vectors , Vector3D , Vector4D
810
911
1012@dataclass
@@ -68,20 +70,22 @@ def __init__(self, matrix: np.ndarray, center_mass: np.ndarray):
6870 self .cm = center_mass # center of mass
6971Translation = np .ndarray
7072
71- def transform (coords : np .ndarray [Vector3D ], T : Translation , R : Rotation ):
73+ def transform (coords : np .ndarray [Vector3D ], translate : Translation = np . array ([ 0 , 0 , 0 ]), rotate : Rotation = Rotation ( np . eye ( 3 ), np . array ([ 0 , 0 , 0 ])) ):
7274 """Transform a set of coordinates by a rotation R and translation T"""
75+ if isinstance (rotate , np .ndarray ):
76+ rotate = Rotation (rotate , np .array ([0 , 0 , 0 ]))
7377 assert coords .shape [0 ] == 3
74- assert T .shape == (3 ,)
75- assert R .M .shape == (3 , 3 )
76- assert R .cm .shape == (3 ,)
78+ assert translate .shape == (3 ,)
79+ assert rotate .M .shape == (3 , 3 )
80+ assert rotate .cm .shape == (3 ,)
7781
7882 # The transform is:
7983 # v' = R*(v - R_cm) + R_cm + T
8084 # = R*v - R*R_cm + R_cm + T
81- # = R*v + (-R*R_cm + R_cm + T)
85+ # = R*v + T'
8286
83- Tp = - np .dot (R .M , R .cm ) + R .cm + T
84- return np .dot (R .M , coords ) + Tp [:, np .newaxis ]
87+ Tp = - np .dot (rotate .M , rotate .cm ) + rotate .cm + translate
88+ return np .dot (rotate .M , coords ) + Tp [:, np .newaxis ]
8589
8690
8791class GeneratePoints :
@@ -226,7 +230,7 @@ def onCheckOverlap(
226230
227231 if any (r != 0 for r in rotation ):
228232 ## effective coordinates, shifted by (x_com,y_com,z_com)
229- x_eff , y_eff , z_eff = Translation ( x , y , z , - com [0 ], - com [1 ], - com [2 ]). onTranslatingPoints ( )
233+ x_eff , y_eff , z_eff = transform ( np . vstack ([ x , y , z ]), translate = np . array ([ - com [0 ], - com [1 ], - com [2 ]]) )
230234
231235 #rotate backwards with minus rotation angles
232236 alpha , beta , gam = rotation
@@ -235,12 +239,12 @@ def onCheckOverlap(
235239 beta = np .radians (beta )
236240 gam = np .radians (gam )
237241
238- x_eff , y_eff , z_eff = Rotation (x_eff , y_eff , z_eff , - alpha , - beta , - gam , rotp_x , rotp_y , rotp_z ).onRotatingPoints ()
242+ rotation = Rotation (euler_rotation_matrix (- alpha , - beta , - gam ), np .array ([rotp_x , rotp_y , rotp_z ]))
243+ x_eff , y_eff , z_eff = transform (np .vstack ([x_eff , y_eff , z_eff ]), rotate = rotation )
239244
240245 else :
241246 ## effective coordinates, shifted by (x_com,y_com,z_com)
242- x_eff , y_eff , z_eff = Translation (x , y , z , - com [0 ], - com [1 ], - com [2 ]).onTranslatingPoints ()
243-
247+ x_eff , y_eff , z_eff = transform (np .vstack ([x , y , z ]), translate = np .array ([- com [0 ], - com [1 ], - com [2 ]]))
244248
245249 idx = subunitClass (dimensions ).checkOverlap (x_eff , y_eff , z_eff )
246250 x_add , y_add , z_add , p_add = x [idx ], y [idx ], z [idx ], p [idx ]
0 commit comments