Commits

German Larrain committed 5c22b66

contants: moved here the geometry ones (plus `pi`) from 'utils.mathematical'. Also:
-removed {RIGHT, UP, OUT}WARDS_AXIS.
-renamed {right, left, up, down, bkwd, fwd}Axis to {RIGHT, LEFT, UP, DOWN, OUT, IN}_AXIS.

  • Participants
  • Parent commits 6fc42f7

Comments (0)

Files changed (6)

File ars/constants.py

+from math import pi
+
 from .utils.mathematical import mult_by_scalar3
 
 #==============================================================================
 # GEOMETRY
 #==============================================================================
 
-X_AXIS = (1,0,0)
-Y_AXIS = (0,1,0)
-Z_AXIS = (0,0,1)
+X_AXIS = (1.0, 0.0, 0.0)
+X_AXIS_NEG = (-1.0, 0.0, 0.0)
+Y_AXIS = (0.0, 1.0, 0.0)
+Y_AXIS_NEG = (0.0, -1.0, 0.0)
+Z_AXIS = (0.0, 0.0, 1.0)
+Z_AXIS_NEG = (0.0, 0.0, -1.0)
 
-RIGHTWARDS_AXIS = X_AXIS
-UPWARDS_AXIS = Y_AXIS
-OUTWARDS_AXIS = Z_AXIS
-
+RIGHT_AXIS = X_AXIS
+LEFT_AXIS = X_AXIS_NEG
+UP_AXIS = Y_AXIS
+DOWN_AXIS = Y_AXIS_NEG
+OUT_AXIS = Z_AXIS  # out of the screen
+IN_AXIS = Z_AXIS_NEG  # into the screen
 
 #==============================================================================
 # MATH & ALGEBRA

File ars/utils/geometry.py

 
 	"""
 	# THE FOLLOWING worked only in some cases, damn
-	#y_up = mut.upAxis
-	#z_front = mut.bkwdAxis
-	#x_right = mut.rightAxis
+	#y_up = UP_AXIS
+	#z_front = OUT_AXIS
+	#x_right = RIGHT_AXIS
 	#
 	#up_rotated = mut.rotate3(rot, y_up)
 	#pitch_proj = mut.dot_product(mut.cross_product(y_up, up_rotated), x_right)

File ars/utils/mathematical.py

 downRot = (1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0)
 bkwdRot = (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)
 
-X_AXIS = (1.0, 0.0, 0.0)
-X_AXIS_NEG = (-1.0, 0.0, 0.0)
-Y_AXIS = (0.0, 1.0, 0.0)
-Y_AXIS_NEG = (0.0, -1.0, 0.0)
-Z_AXIS = (0.0, 0.0, 1.0)
-Z_AXIS_NEG = (0.0, 0.0, -1.0)
-
-# axes used to determine constrained joint rotations
-rightAxis = X_AXIS
-leftAxis = X_AXIS_NEG
-upAxis = Y_AXIS
-downAxis = Y_AXIS_NEG
-bkwdAxis = Z_AXIS  # direction: out of the screen
-fwdAxis = Z_AXIS_NEG  # direction: into the screen
-
 #==============================================================================
 # added to the original refactored code
 #==============================================================================

File demos/sensors/laser.py

+from ars.constants import Z_AXIS
 from ars.graphics import adapters as graphics_adapter
 from ars.lib.pydispatch import dispatcher
 from ars.model.robot import sensors
 		laser_pos = ray.get_position()
 		laser_rot = ray.get_rotation()
 
-		distance_vector = mut.mult_by_scalar3(mut.Z_AXIS, distance)
+		distance_vector = mut.mult_by_scalar3(Z_AXIS, distance)
 		offset = mut.rotate3(laser_rot, distance_vector)
 		position = mut.add3(laser_pos, offset)
 		return position

File tests/utils_geometry.py

 
 import numpy as np
 
+from ars.constants import (DOWN_AXIS, IN_AXIS, LEFT_AXIS, OUT_AXIS, pi,
+                           RIGHT_AXIS, UP_AXIS)
 import ars.utils.geometry as gemut
-import ars.utils.mathematical as mut
 
 
 def _test_Transform():
 	print(ht3)
 
 def test_calc_inclination(axis, angle):
-	#axis = mut.upAxis
-	#angle = mut.pi/4
+	#axis = UP_AXIS
+	#angle = pi / 4
 	rot = gemut.calc_rotation_matrix(axis, angle)
 	pitch, roll = gemut.calc_inclination(rot)
 	print('axis: %s, angle: %f' % (axis, angle))
 
 	# rotation around axii perpendicular to the ground does not affect
 	# the inclination
-	test_calc_inclination(mut.upAxis, mut.pi/4)
-	test_calc_inclination(mut.upAxis, 3*mut.pi/9)
-	test_calc_inclination(mut.upAxis, -mut.pi/8)
-	test_calc_inclination(mut.downAxis, mut.pi/4)
-	test_calc_inclination(mut.downAxis, 3*mut.pi/9)
-	test_calc_inclination(mut.downAxis, -mut.pi/8)
+	test_calc_inclination(UP_AXIS, pi / 4)
+	test_calc_inclination(UP_AXIS, 3 * pi / 9)
+	test_calc_inclination(UP_AXIS, -pi / 8)
+	test_calc_inclination(DOWN_AXIS, pi / 4)
+	test_calc_inclination(DOWN_AXIS, 3 * pi / 9)
+	test_calc_inclination(DOWN_AXIS, -pi / 8)
 
-	test_calc_inclination(mut.rightAxis, mut.pi/6)
-	test_calc_inclination(mut.rightAxis, 3*mut.pi/9)
-	test_calc_inclination(mut.rightAxis, -mut.pi/8)
-	test_calc_inclination(mut.leftAxis, mut.pi/8)
-	test_calc_inclination(mut.bkwdAxis, mut.pi/8)
+	test_calc_inclination(RIGHT_AXIS, pi / 6)
+	test_calc_inclination(RIGHT_AXIS, 3 * pi / 9)
+	test_calc_inclination(RIGHT_AXIS, -pi / 8)
+	test_calc_inclination(LEFT_AXIS, pi / 8)
+	test_calc_inclination(OUT_AXIS, pi / 8)
 
 
-	test_calc_compass_angle(mut.upAxis, mut.pi/8)
-	test_calc_compass_angle(mut.upAxis, -mut.pi/8)
-	test_calc_compass_angle(mut.upAxis, 3.0 * mut.pi / 2)
-	test_calc_compass_angle(mut.downAxis, mut.pi/8)
-	test_calc_compass_angle(mut.downAxis, -mut.pi/8)
-	test_calc_compass_angle(mut.rightAxis, mut.pi/8)
-	test_calc_compass_angle(mut.leftAxis, mut.pi/8)
-	test_calc_compass_angle(mut.bkwdAxis, mut.pi/8)
-	test_calc_compass_angle(mut.fwdAxis, mut.pi/8)
+	test_calc_compass_angle(UP_AXIS, pi / 8)
+	test_calc_compass_angle(UP_AXIS, -pi / 8)
+	test_calc_compass_angle(UP_AXIS, 3.0 * pi / 2)
+	test_calc_compass_angle(DOWN_AXIS, pi / 8)
+	test_calc_compass_angle(DOWN_AXIS, -pi / 8)
+	test_calc_compass_angle(RIGHT_AXIS, pi / 8)
+	test_calc_compass_angle(LEFT_AXIS, pi / 8)
+	test_calc_compass_angle(OUT_AXIS, pi / 8)
+	test_calc_compass_angle(IN_AXIS, pi / 8)
 

File tests/utils_mathematical.py

 
 
 def test_XYZ_axes_for_orthogonality():
-	X = mut.X_AXIS
-	Y = mut.Y_AXIS
-	Z = mut.Z_AXIS
+	from ars.constants import X_AXIS, Y_AXIS, Z_AXIS
+
+	X = X_AXIS
+	Y = Y_AXIS
+	Z = 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))