branch | pyrit |
changeset 72 | 7c3f38dff082 |
71:4fedf7290929 | 72:7c3f38dff082 |
---|---|
1 from math import * |
|
2 |
|
3 def dot(a,b): |
|
4 sum = 0 |
|
5 for i in range(min(len(a),len(b))): |
|
6 sum += a[i]*b[i] |
|
7 return sum |
|
8 |
|
9 def cross(a,b): |
|
10 return ( |
|
11 a[1]*b[2] - a[2]*b[1], |
|
12 a[2]*b[0] - a[0]*b[2], |
|
13 a[0]*b[1] - a[1]*b[0] |
|
14 ) |
|
15 |
|
16 def unit(a): |
|
17 m = mag(a) |
|
18 return (a[0]/m, a[1]/m, a[2]/m) |
|
19 |
|
20 def mag(a): |
|
21 return sqrt(mag2(a)) |
|
22 |
|
23 def mag2(a): |
|
24 return a[0]*a[0] + a[1]*a[1] + a[2]*a[2] |