sympy / sympy

A computer algebra system written in pure Python
https://sympy.org/
Other
13k stars 4.44k forks source link

bug in diffgeom for conversion between coordinate systems #6656

Open rochabm opened 11 years ago

rochabm commented 11 years ago
I'm trying to create a simple script to convert the coordinates (x,y,z)
from one system to another coordinate system (r,theta,phi).

The parametric equations for x,y,z are given by
x = (a1 + r*(a2-a1)) * cos(theta) * cos(phi)
y = (a1 + r*(a2-a1)) * cos(theta) * sin(phi)
z = (c1 + r*(c2-c1)) * sin(theta)

This is my code :

r, theta, phi = symbols('r, theta, phi')
m = Manifold('M', 2)
patch = Patch('P', m)
rect = CoordSystem('rect', patch)
ellip = CoordSystem('ellip', patch)

# Connect the coordinate systems
# An inverse transformation is automatically found by solve when
possible
a1, a2 = 1.1, 1.7
c1, c2 = 2.5, 2.8

a = a1+r*(a2-a1)
c = c1+r*(c2-c1)

ellip.connect_to(rect, [r,theta,phi], [a*cos(theta)*cos(phi),
a*cos(theta)*sin(phi), c*sin(theta)])

then I have the following error:

Manifold(M, 2)
Patch(P, Manifold(M, 2))
Traceback (most recent call last):
File "ellipsoid.py", line 24, in <module>
ellip.connect_to(rect, [r,theta,phi], [a*cos(theta)*cos(phi),
a*cos(theta)*sin(phi), c*sin(theta)])
File "/usr/lib/python3.3/site-packages/sympy/diffgeom/diffgeom.py", line
217, in connect_to
to_sys.transforms[self] = self._inv_transf(from_coords, to_exprs)
File "/usr/lib/python3.3/site-packages/sympy/diffgeom/diffgeom.py", line
232, in _inv_transf
inv_to = inv_to[0]
IndexError: list index out of range

Original issue for #6656: http://code.google.com/p/sympy/issues/detail?id=3557 Original author: https://code.google.com/u/104691503752462166427/

asmeurer commented 11 years ago
Issue 3558 has been merged into this issue.

Original comment: http://code.google.com/p/sympy/issues/detail?id=3557#c1 Original author: https://code.google.com/u/asmeurer@gmail.com/

asmeurer commented 11 years ago
Two issues here:

solve can't find the solution. Supposedly, it should raise NotImplementedError instead of returning []. 

diffgeom should be robust against this, as solve has no guarantees.

**Status:** Valid  
**Labels:** Solvers  

Original comment: http://code.google.com/p/sympy/issues/detail?id=3557#c2 Original author: https://code.google.com/u/asmeurer@gmail.com/