demos/vector.py
author Radek Brich <radek.brich@devl.cz>
Thu, 24 Apr 2008 18:12:32 +0200
branchpyrit
changeset 83 e3a2a5b26abb
parent 72 7c3f38dff082
permissions -rw-r--r--
vectorize makeRayPacket() using SSE intrinsics
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
72
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
from math import *
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
def dot(a,b):
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
	sum = 0
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
	for i in range(min(len(a),len(b))):
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
		sum += a[i]*b[i]
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
	return sum
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
def cross(a,b):
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
	return (
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
		a[1]*b[2] - a[2]*b[1],
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
		a[2]*b[0] - a[0]*b[2],
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
		a[0]*b[1] - a[1]*b[0]
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
	)
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
def unit(a):
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
	m = mag(a)
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
	return (a[0]/m, a[1]/m, a[2]/m)
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
def mag(a):
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
	return sqrt(mag2(a))
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
def mag2(a):
7c3f38dff082 kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
	return a[0]*a[0] + a[1]*a[1] + a[2]*a[2]