summaryrefslogtreecommitdiff
path: root/project.py
diff options
context:
space:
mode:
authorAnthony LaTorre <tlatorre9@gmail.com>2011-08-25 21:35:53 -0400
committerAnthony LaTorre <tlatorre9@gmail.com>2011-08-25 21:35:53 -0400
commitfb7c8c279de91b4c8db4e858df2891d650e4a304 (patch)
treeb70676f06cf256effcb9109e452eb12a9064a0d3 /project.py
parent327ed839411ea8304db184cd6c428c5805252cd1 (diff)
downloadchroma-fb7c8c279de91b4c8db4e858df2891d650e4a304.tar.gz
chroma-fb7c8c279de91b4c8db4e858df2891d650e4a304.tar.bz2
chroma-fb7c8c279de91b4c8db4e858df2891d650e4a304.zip
add library for projecting rays in different ways.
Diffstat (limited to 'project.py')
-rw-r--r--project.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/project.py b/project.py
new file mode 100644
index 0000000..801a4de
--- /dev/null
+++ b/project.py
@@ -0,0 +1,28 @@
+import numpy as np
+from itertools import repeat
+from chroma.transform import rotate
+
+def from_film(position, axis1=(0,0,1), axis2=(1,0,0), size=(800,600), width=0.035, focal_length=0.018):
+ height = width*(size[1]/float(size[0]))
+
+ x = np.linspace(width/2, -width/2, size[0])
+ z = np.linspace(-height/2, height/2, size[1])
+
+ zz, xx = np.meshgrid(z,x)
+
+ grid = np.array(zip(xx.flatten(),repeat(0),zz.flatten()))
+
+ axis1 = np.asarray(axis1)/np.linalg.norm(axis1)
+ axis2 = np.asarray(axis2)/np.linalg.norm(axis2)
+
+ assert axis1.dot(axis2) == 0.0
+
+ if (axis1 != (0,0,1)).any():
+ grid = rotate(grid, np.arccos(axis1.dot((0,0,1))), np.cross(axis1,(0,0,1)))
+
+ if (axis2 != (1,0,0)).any():
+ grid = rotate(grid, np.arccos(axis2.dot((1,0,0))), np.cross(axis2,(1,0,0)))
+
+ grid -= np.cross(axis1,axis2)*focal_length
+
+ return grid+position, -grid/np.apply_along_axis(np.linalg.norm,1,grid)[:,np.newaxis]