From 8dfc46b06d7aa98fb272c9b73a9573e14722d66d Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Mon, 16 Apr 2012 11:18:33 -0400 Subject: Raise an exception if a zero 3-vector is passed to make_rotation_matrix() --- chroma/transform.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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]]) -- cgit