Skip to content

Commit

Permalink
Merge pull request #13040 from szymag/trans_equations_translation
Browse files Browse the repository at this point in the history
Add _translation_trans_equations method.
  • Loading branch information
Upabjojr committed Jul 27, 2017
2 parents 204f598 + 609a701 commit 9156b07
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sympy/vector/coordsysrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,30 @@ def _rotation_trans_equations(self, matrix):

return trans_eq1, trans_eq2, trans_eq3

def _translation_trans_equations(self, inverse=False):
"""
Returns the transformation equations obtained from translation
vector. Translation vector is defined as a linking vector of
origins of two coordinate systems.
"""
if inverse:
sign = -1
else:
sign = 1

if self._parent is None:
return self.base_scalars()
else:
vec_component = self._origin.position_wrt(self._parent).components
vec_norm_projections = []
for i in self._parent.base_vectors():
try:
vec_norm_projections.append(sign * vec_component[i])
except:
vec_norm_projections.append(0)
return tuple([sum(i) for i in zip(vec_norm_projections, self.base_scalars())])

@property
def origin(self):
return self._origin
Expand Down
14 changes: 14 additions & 0 deletions sympy/vector/tests/test_coordsysrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,17 @@ def test_rotation_trans_equations():
(-sin(q0) * c.y + cos(q0) * c.x, sin(q0) * c.x + cos(q0) * c.y, c.z)
assert c._rotation_trans_equations(c._inverse_rotation_matrix()) == \
(sin(q0) * c.y + cos(q0) * c.x, -sin(q0) * c.x + cos(q0) * c.y, c.z)

def test_translation_trans_equations():
from sympy import symbols
q0 = symbols('q0')
a = CoordSys3D('a')
assert a._translation_trans_equations() == (a.x, a.y, a.z)
b = a.locate_new('b', None)
assert b._translation_trans_equations() == (b.x, b.y, b.z)
assert b._translation_trans_equations(inverse=True) == (b.x, b.y, b.z)
c = a.locate_new('c', (a.i + a.j + a.k))
assert c._translation_trans_equations() == (c.x + 1, c.y + 1, c.z + 1)
d = a.locate_new('d', (a.i + a.j + Vector.zero))
assert d._translation_trans_equations() == (d.x + 1, d.y + 1, d.z)
assert d._translation_trans_equations(inverse=True) == (d.x - 1, d.y - 1, d.z)

0 comments on commit 9156b07

Please sign in to comment.