demos/vector.py
author Radek Brich <radek.brich@devl.cz>
Tue, 29 Apr 2008 23:31:08 +0200
branchpyrit
changeset 90 f6a72eb99631
parent 72 7c3f38dff082
permissions -rw-r--r--
rename Python module from 'raytracer' to 'pyrit' improve Python binding: - new objects: Container, Octree, KdTree, Shape, Pixmap, Sampler, DefaultSampler - all shapes are now subclasses of Shape - clean, remove redundant Getattr's - Raytracer render method now just wraps C++ method without doing any additional work adjust all demos for changes in Python binding, remove PIL dependency add demo_PIL.py as a example of pyrit + PIL usage render_nff.py now either loads file given as a argument or reads input from stdin otherwise fix bug in pixmap float to char conversion

from math import *

def dot(a,b):
	sum = 0
	for i in range(min(len(a),len(b))):
		sum += a[i]*b[i]
	return sum

def cross(a,b):
	return (
		a[1]*b[2] - a[2]*b[1],
		a[2]*b[0] - a[0]*b[2],
		a[0]*b[1] - a[1]*b[0]
	)

def unit(a):
	m = mag(a)
	return (a[0]/m, a[1]/m, a[2]/m)

def mag(a):
	return sqrt(mag2(a))

def mag2(a):
	return a[0]*a[0] + a[1]*a[1] + a[2]*a[2]