diff options
| author | Anthony LaTorre <telatorre@gmail.com> | 2011-06-01 17:00:37 -0400 |
|---|---|---|
| committer | Anthony LaTorre <telatorre@gmail.com> | 2011-06-01 17:00:37 -0400 |
| commit | d0825a136ff65b36069ff8b078b9fd97adeed0df (patch) | |
| tree | ca47a0bfb495d8795e3fba7c7315215a5d7f5513 /transform.py | |
| parent | b0f5fa8f463136ee8fb5401b3aa76d1b087997d2 (diff) | |
| download | chroma-d0825a136ff65b36069ff8b078b9fd97adeed0df.tar.gz chroma-d0825a136ff65b36069ff8b078b9fd97adeed0df.tar.bz2 chroma-d0825a136ff65b36069ff8b078b9fd97adeed0df.zip | |
first step towards moving to a new mesh/solid/geometry structure
Diffstat (limited to 'transform.py')
| -rw-r--r-- | transform.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/transform.py b/transform.py index 1321c8c..ef8c96c 100644 --- a/transform.py +++ b/transform.py @@ -1,16 +1,24 @@ import numpy as np +def make_rotation_matrix(phi, n): + """ + Make the rotation matrix to rotate points through an angle `phi` + counter-clockwise around the axis `n` (when looking towards +infinity). + + Source: Weissten, Eric W. "Rotation Formula." Mathworld. + """ + n = np.asarray(n)/np.linalg.norm(n) + + 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]]) + def rotate(x, phi, n): """ Rotate an array of points `x` through an angle phi counter-clockwise around the axis `n` (when looking towards +infinity). - - Source: Weisstein, Eric W. "Rotation Formula." Mathworld. """ x = np.asarray(x) - n = np.asarray(n)/np.linalg.norm(n) - r = 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]]) + r = make_rotation_matrix(phi, n) return np.inner(x,r) |
