diff options
author | Stan Seibert <stan@mtrr.org> | 2012-04-16 11:18:33 -0400 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:38 -0700 |
commit | 8dfc46b06d7aa98fb272c9b73a9573e14722d66d (patch) | |
tree | 438ef6476042e975203ad76a2b43e579e01d091b | |
parent | d897ca61af1086cf3360717f7978c4be733b3f1c (diff) | |
download | chroma-8dfc46b06d7aa98fb272c9b73a9573e14722d66d.tar.gz chroma-8dfc46b06d7aa98fb272c9b73a9573e14722d66d.tar.bz2 chroma-8dfc46b06d7aa98fb272c9b73a9573e14722d66d.zip |
Raise an exception if a zero 3-vector is passed to make_rotation_matrix()
-rw-r--r-- | chroma/transform.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/chroma/transform.py b/chroma/transform.py index 299da46..76b1939 100644 --- a/chroma/transform.py +++ b/chroma/transform.py @@ -6,8 +6,13 @@ def make_rotation_matrix(phi, n): counter-clockwise around the axis `n` (when looking towards +infinity). Source: Weissten, Eric W. "Rotation Formula." Mathworld. + + Raises ValueError if n has zero magnitude """ - n = np.asarray(n)/np.linalg.norm(n) + norm = np.linalg.norm(n) + if norm == 0.0: + raise ValueError('rotation axis has zero magnitude') + n = np.asarray(n)/norm return np.cos(phi)*np.identity(3) + (1-np.cos(phi))*np.outer(n,n) + \ np.sin(phi)*np.array([[0,n[2],-n[1]],[-n[2],0,n[0]],[n[1],-n[0],0]]) |