about summary refs log tree commit diff homepage
path: root/utils/hacks/TreeGraphs/Graphics/Geometry/mat3.py
blob: d2c23b1b845854584961520d41feef38e6889a89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# ===-- mat3.py -----------------------------------------------------------===##
# 
#                      The KLEE Symbolic Virtual Machine
# 
#  This file is distributed under the University of Illinois Open Source
#  License. See LICENSE.TXT for details.
# 
# ===----------------------------------------------------------------------===##

import vec3,mat2

def identity():
	return ((1.0, 0.0, 0.0),
			(0.0, 1.0, 0.0),
			(0.0, 0.0, 1.0))

def fromscale(scale):
	x,y,z= scale
	x,y,z= float(x),float(y),float(z)
	return ((  x, 0.0, 0.0),
			(0.0,   y, 0.0),
			(0.0, 0.0,   z))
def fromscaleN(n):
	return fromscale((n,n,n))

def mul(a,b):
	b_trans= zip(* b)
	return tuple([transmulvec3(b_trans, a_r) for a_r in a])

	# multiple vector v by a transposed matrix
def transmulvec3(m_trans,v):
	return tuple([vec3.dot(v, m_c) for m_c in m_trans])

def mulvec3(m,v):
	return transmulvec3(zip(* m), v)

def mulN(m,N):
	return tuple([vec3.mulN(v,N) for v in m])

def det(m):
	((m00,m01,m02),
	 (m10,m11,m12),
	 (m20,m21,m22))= m

	a= m00 * mat2.det( ((m11, m12), (m21, m22)) );
	b= m10 * mat2.det( ((m01, m02), (m21, m22)) );
	c= m20 * mat2.det( ((m01, m02), (m11, m12)) );
	
	return a-b+c