Ask Your Question
1

Coordinate Transforms

asked 2013-03-31 20:04:28 +0100

Convenient Truth gravatar image

Is there something in sage that does the same thing that CoordinateTransform and TransformedField in Mathematica 9 ?

The idea is that CoordinateTransform is given some coordinates, e.g. (r,th) and asked to transform them from "polar" to "cartesian", thus gives the expression of the cartesian coordinates in terms of the polar coordinates, e.g.

(x(r,th), y(r,th)) = (r*cos(th), r*sin(th))

Obvioulsly, it also works with other coordinates systems.

TransformedField makes the transformation between a scalar, vector, or tensor field in, say, cartesian coordinates, to spherical coordinates.

These actions are not very complicated, nor difficult to implement when needed, but they are also very common.

Thanks.

references :

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-04-01 06:19:35 +0100

Jason Grout gravatar image

updated 2013-04-01 06:19:44 +0100

You can define functions to act as transformations:

T(r,theta) = (r*sin(theta), r*cos(theta))

and then just use them as normal functions: T(2,pi/2)

Also, you can pass an arbitrary 3d transformation to 3d plots using the transformation keyword. See the examples in the plot3d documentation. See also the builtin Spherical and Cylindrical transformations, or even the spherical_plot3d or cylindrical_plot3d functions.

It would be cool to have a transformation module that defines a bunch of transformations for convenience.

edit flag offensive delete link more
2

answered 2016-08-21 18:25:03 +0100

eric_g gravatar image

updated 2016-08-21 20:36:53 +0100

Since SageMath 7.3, it's possible to deal with coordinate transforms as transition maps between charts on a manifold. For instance, the transition from polar to Cartesian coordinates in the Euclidean plane is defined as follows:

sage: M = Manifold(2, 'M') # the Euclidean plane
sage: Cart.<x,y> = M.chart()  # Cartesian coordinates (x,y)
sage: Polar.<r,th> = M.chart(r'r:(0,+oo) th:(0,2*pi):\theta') # polar coordinates (r,th)
sage: Polar_to_Cart = Polar.transition_map(Cart, [r*cos(th), r*sin(th)])
sage: Polar_to_Cart.display()
x = r*cos(th)
y = r*sin(th)
sage: Polar_to_Cart.set_inverse(sqrt(x^2+y^2), atan2(y,x))
sage: Cart_to_Polar = Polar_to_Cart.inverse()
sage: Cart_to_Polar.display()
r = sqrt(x^2 + y^2)
th = arctan2(y, x)

The examples in the CoordinateTransform Mathematica page referred to in the question are then

sage: Polar_to_Cart(r,th)
(r*cos(th), r*sin(th))
sage: Cart_to_Polar(1,-1)
(sqrt(2), -1/4*pi)

The first example of the TransformedField Mathematica page becomes

sage: f = M.scalar_field({Polar: r^2*cos(th)}, name='f')
sage: f.expr(Cart)
sqrt(x^2 + y^2)*x
sage: f.display()
f: M --> R
   (x, y) |--> sqrt(x^2 + y^2)*x
   (r, th) |--> r^2*cos(th)

The second example of TransformedField involves a vector field. Since vector fields on manifolds are not included in SageMath yet (but should be soon), one has to install SageManifolds atop SageMath 7.3 to deal with them. The Mathematica example becomes then:

sage: e_x, e_y = Cart.frame()[0], Cart.frame()[1]
sage: v = x*e_x + y*e_y
sage: v.display()
x d/dx + y d/dy
sage: v[:]
[x, y]
sage: v[Polar.frame(), :, Polar]
[r, 0]
sage: v.display(Polar.frame(), Polar)
r d/dr

Another example, involving coordinate transforms between 6 charts on the hyperbolic plane, is here.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-03-31 20:04:28 +0100

Seen: 3,031 times

Last updated: Aug 21 '16