Source

ars / tests / utils_mathematical.py

Full commit
import numpy

import ars.utils.mathematical as mut


def _vector_diff_length(v1, v2):
	return mut.length3(mut.sub3(v1, v2))

def test_np_matrix_to_tuple():
	arr = numpy.array(((2, 2), (2, -2)))
	print(mut.np_matrix_to_tuple(arr))

def test_matrix_as_tuple():
	print(mut.matrix_as_tuple(((1, 2), (3, 4))))


def test_matrix_multiply():
	print (mut.matrix_multiply(((2,),(1,)), ((1,0,0,0,2,0,0,0,1), )))
	print (mut.matrix_multiply(((2,0,0),(0,1,0),(0,0,1)),
		((1,0,0),(0,2,0),(0,0,1))))
	print (mut.matrix_multiply(((2,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)),
		((1,0,0,0),(0,2,0,0),(0,0,1,0),(0,0,0,1))))


def test_calc_acceleration():
	print('%s, %s' % (0.0,
					  mut.calc_acceleration(0.01, (15,-1.5,84), (15,-1.5,84))))
	print('%s, %s' % (100.0, mut.calc_acceleration(0.01, (0,0,1), (0,0,2))))
	print('%s, %s' % (-100.0, mut.calc_acceleration(0.01, (0,0,2), (0,0,1))))
	print('%s, %s' % (141.421, mut.calc_acceleration(0.01, (0,1,0), (0,0,1))))


def test_XYZ_axes_for_orthogonality():
	X = mut.X_AXIS
	Y = mut.Y_AXIS
	Z = mut.Z_AXIS
	print(_vector_diff_length(mut.cross_product(X, Y), Z))
	print(_vector_diff_length(mut.cross_product(Z, X), Y))
	print(_vector_diff_length(mut.cross_product(Y, Z), X))

if __name__ == "__main__":

	test_np_matrix_to_tuple()
	test_matrix_as_tuple()
	test_matrix_multiply()
	test_XYZ_axes_for_orthogonality()
	test_calc_acceleration()