added explicit method Rotation.fromBasis, which can treat real and reciprocal basis sets
This commit is contained in:
parent
7c22c88df5
commit
4c7af713f1
|
@ -227,12 +227,17 @@ class Rotation:
|
||||||
return cls(ax2qu(ax))
|
return cls(ax2qu(ax))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromMatrix(cls,
|
def fromBasis(cls,
|
||||||
matrix,
|
basis,
|
||||||
containsStretch = False): #ToDo: better name?
|
orthonormal = True,
|
||||||
|
reciprocal = False,
|
||||||
|
):
|
||||||
|
|
||||||
om = matrix if isinstance(matrix, np.ndarray) else np.array(matrix).reshape((3,3)) # ToDo: Reshape here or require explicit?
|
om = basis if isinstance(basis, np.ndarray) else np.array(basis).reshape((3,3))
|
||||||
if containsStretch:
|
if reciprocal:
|
||||||
|
om = np.linalg.inv(om.T/np.pi) # transform reciprocal basis set
|
||||||
|
orthonormal = False # contains stretch
|
||||||
|
if not orthonormal:
|
||||||
(U,S,Vh) = np.linalg.svd(om) # singular value decomposition
|
(U,S,Vh) = np.linalg.svd(om) # singular value decomposition
|
||||||
om = np.dot(U,Vh)
|
om = np.dot(U,Vh)
|
||||||
if not np.isclose(np.linalg.det(om),1.0):
|
if not np.isclose(np.linalg.det(om),1.0):
|
||||||
|
@ -244,6 +249,13 @@ class Rotation:
|
||||||
|
|
||||||
return cls(om2qu(om))
|
return cls(om2qu(om))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def fromMatrix(cls,
|
||||||
|
om,
|
||||||
|
):
|
||||||
|
|
||||||
|
return cls.fromBasis(om)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromRodrigues(cls,
|
def fromRodrigues(cls,
|
||||||
rodrigues,
|
rodrigues,
|
||||||
|
|
Loading…
Reference in New Issue