From a6d4c73de0e559f1484930f29e52777c15111b06 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 5 Dec 2018 10:20:05 -0500 Subject: [PATCH] added list of map and introduced "quat" keyword in quaternion init --- lib/damask/orientation.py | 22 ++++++++++++++-------- processing/pre/geom_addPrimitive.py | 8 ++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/damask/orientation.py b/lib/damask/orientation.py index 63fb124a6..c1862e13c 100644 --- a/lib/damask/orientation.py +++ b/lib/damask/orientation.py @@ -72,15 +72,13 @@ class Quaternion: def __pow__(self, exponent): """Power""" - Q = Quaternion() omega = math.acos(self.q) - Q.q = math.cos(exponent*omega) - Q.p = self.p * math.sin(exponent*omega)/math.sin(omega) - return Q + return self.__class__(q= math.cos(exponent*omega), + p=self.p * math.sin(exponent*omega)/math.sin(omega)) def __ipow__(self, exponent): """In-place power""" - omega = math.acos(self.q[0]) + omega = math.acos(self.q) self.q = math.cos(exponent*omega) self.p *= math.sin(exponent*omega)/math.sin(omega) return self @@ -94,9 +92,17 @@ class Quaternion: p=self.q*other.p + other.q*self.p + P * np.cross(self.p,other.p)) except: pass try: # vector (perform passive rotation) - return (self.q*self.q - np.dot(self.p,self.p)) * np.array(other[:3]) \ - + 2.0*np.dot(self.p,other[:3]) * self.p \ - + 2.0*P*self.q * np.cross(self.p,other[:3]) + ( x, y, z) = self.p + (Vx,Vy,Vz) = other[0:3] + A = self.q*self.q - np.dot(self.p,self.p) + B = 2.0 * (x*Vx + y*Vy + z*Vz) + C = 2.0 * P*self.q + + return np.array([ + A*Vx + B*x + C*(y*Vz - z*Vy), + A*Vy + B*y + C*(z*Vx - x*Vz), + A*Vz + B*z + C*(x*Vy - y*Vx), + ]) except: pass try: # scalar return self.__class__(q=self.q*other, diff --git a/processing/pre/geom_addPrimitive.py b/processing/pre/geom_addPrimitive.py index 35000d8bf..54de558f7 100755 --- a/processing/pre/geom_addPrimitive.py +++ b/processing/pre/geom_addPrimitive.py @@ -64,11 +64,11 @@ if options.dimension is None: parser.error('no dimension specified.') if options.angleaxis is not None: options.angleaxis = list(map(float,options.angleaxis)) - rotation = damask.Quaternion().fromAngleAxis(np.radians(options.angleaxis[0]) if options.degrees else options.angleaxis[0], - options.angleaxis[1:4]) + rotation = damask.Quaternion.fromAngleAxis(np.radians(options.angleaxis[0]) if options.degrees else options.angleaxis[0], + options.angleaxis[1:4]) elif options.quaternion is not None: - options.quaternion = map(float,options.quaternion) - rotation = damask.Quaternion(options.quaternion) + options.quaternion = list(map(float,options.quaternion)) + rotation = damask.Quaternion(quat=options.quaternion) else: rotation = damask.Quaternion()