added list of map and introduced "quat" keyword in quaternion init
This commit is contained in:
parent
c0f7ae2798
commit
a6d4c73de0
|
@ -72,15 +72,13 @@ class Quaternion:
|
||||||
|
|
||||||
def __pow__(self, exponent):
|
def __pow__(self, exponent):
|
||||||
"""Power"""
|
"""Power"""
|
||||||
Q = Quaternion()
|
|
||||||
omega = math.acos(self.q)
|
omega = math.acos(self.q)
|
||||||
Q.q = math.cos(exponent*omega)
|
return self.__class__(q= math.cos(exponent*omega),
|
||||||
Q.p = self.p * math.sin(exponent*omega)/math.sin(omega)
|
p=self.p * math.sin(exponent*omega)/math.sin(omega))
|
||||||
return Q
|
|
||||||
|
|
||||||
def __ipow__(self, exponent):
|
def __ipow__(self, exponent):
|
||||||
"""In-place power"""
|
"""In-place power"""
|
||||||
omega = math.acos(self.q[0])
|
omega = math.acos(self.q)
|
||||||
self.q = math.cos(exponent*omega)
|
self.q = math.cos(exponent*omega)
|
||||||
self.p *= math.sin(exponent*omega)/math.sin(omega)
|
self.p *= math.sin(exponent*omega)/math.sin(omega)
|
||||||
return self
|
return self
|
||||||
|
@ -94,9 +92,17 @@ class Quaternion:
|
||||||
p=self.q*other.p + other.q*self.p + P * np.cross(self.p,other.p))
|
p=self.q*other.p + other.q*self.p + P * np.cross(self.p,other.p))
|
||||||
except: pass
|
except: pass
|
||||||
try: # vector (perform passive rotation)
|
try: # vector (perform passive rotation)
|
||||||
return (self.q*self.q - np.dot(self.p,self.p)) * np.array(other[:3]) \
|
( x, y, z) = self.p
|
||||||
+ 2.0*np.dot(self.p,other[:3]) * self.p \
|
(Vx,Vy,Vz) = other[0:3]
|
||||||
+ 2.0*P*self.q * np.cross(self.p,other[: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
|
except: pass
|
||||||
try: # scalar
|
try: # scalar
|
||||||
return self.__class__(q=self.q*other,
|
return self.__class__(q=self.q*other,
|
||||||
|
|
|
@ -64,11 +64,11 @@ if options.dimension is None:
|
||||||
parser.error('no dimension specified.')
|
parser.error('no dimension specified.')
|
||||||
if options.angleaxis is not None:
|
if options.angleaxis is not None:
|
||||||
options.angleaxis = list(map(float,options.angleaxis))
|
options.angleaxis = list(map(float,options.angleaxis))
|
||||||
rotation = damask.Quaternion().fromAngleAxis(np.radians(options.angleaxis[0]) if options.degrees else options.angleaxis[0],
|
rotation = damask.Quaternion.fromAngleAxis(np.radians(options.angleaxis[0]) if options.degrees else options.angleaxis[0],
|
||||||
options.angleaxis[1:4])
|
options.angleaxis[1:4])
|
||||||
elif options.quaternion is not None:
|
elif options.quaternion is not None:
|
||||||
options.quaternion = map(float,options.quaternion)
|
options.quaternion = list(map(float,options.quaternion))
|
||||||
rotation = damask.Quaternion(options.quaternion)
|
rotation = damask.Quaternion(quat=options.quaternion)
|
||||||
else:
|
else:
|
||||||
rotation = damask.Quaternion()
|
rotation = damask.Quaternion()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue