(* Koordinatensysteme, WQ, FS 2013 *)

({{, CoordinateTransformData[t,property] 
gives the value of the specified property for the coordinate transformation t.}, {, 
CoordinateTransformData[t,property,{(Subscript[x, 1]),(Subscript[x, 2]),…,(Subscript[x, n])}]
gives the value of the property evaluated at the point {(Subscript[x, 1]),(Subscript[x, 2]),…,(Subscript[x, n])}.}})

(* Beispiel Polarkoordinaten 2-dimensional *)

CoordinateTransformData["Cartesian"->"Polar", "Mapping", {x,y}]

CoordinateTransformData["Cartesian"->"Polar", "MappingJacobian", {x,y}]
CoordinateTransformData["Cartesian"->"Polar", "MappingJacobianDeterminant", {x,y}]

(* In der Ausgabe ist eine 'Kurzform' verwendet: 
ArcTan[x,y] gives the arc tangent of y/x,taking into account which quadrant the point(x,y) is in. *)

(* The mapping function can be requested from CoordinateTransformData and stored for later use. *)

map=CoordinateTransformData["Cartesian"->"Polar", "Mapping"]

map[{1,1}]

map /@ {{0,1},{1,0}, {1/2,1/2}, {3,1/3}}

CoordinateTransformData["Polar"->"Cartesian", "Mapping", {r,θ}]

mp=CoordinateTransformData["Polar"->"Cartesian", "MappingJacobian", {r,θ}]

imp=CoordinateTransformData[{"Polar"->"Cartesian","Euclidean",2}, "InverseMappingJacobian", {r,θ}]

CoordinateTransformData["Polar"->"Cartesian", "MappingJacobianDeterminant", {r,θ}]

mp . imp // Simplify

(*  Anwendung der Transformation von {x,y} zu {r,θ} *)
pt=CoordinateTransform["Cartesian"->"Polar", {x,y}]

(* Und zurueck *)
CoordinateTransform["Polar"->"Cartesian", pt]

Example: Convert a curve in non-Cartesian coordinates 
to a corresponding Cartesian expression for purposes of visualization:

cSpherical[t_] := {t, Pi(((1+Sin[16t+4t^2])/2)), 1+2t+3t^2}

cCartesian[t_] = CoordinateTransform["Spherical"->"Cartesian",cSpherical[t]]

Show[Graphics3D[{Opacity[.25],Sphere[]}],ParametricPlot3D[cCartesian[t],{t,0,1},PlotStyle->Thick,ColorFunction->(Hue[.8#4]&)]]

This curve is approximately 11.2 radii in length:

NIntegrate[Sqrt[cCartesian'[t].cCartesian'[t]],{t,0,1}]

(* in den Sphericals ist es schwieriger, siehe unten: *)
metr=CoordinateChartData[{"Spherical",3},"Metric"][{r,θ,φ}] /. {r-> t,θ->Pi(((1+Sin[16t+4t^2])/2))}

NIntegrate[Sqrt[cSpherical'[t].metr.cSpherical'[t]],{t,0,1}]

(* Koordinaten  --  Karten  *)

CoordinateChartData["Properties"]

CoordinateChartData["Polar", "ScaleFactors", {r,θ}]

CoordinateChartData[{"Polar",2}, "ScaleFactors", {r,θ}]

CoordinateChartData["Polar", "Metric", {r,θ}]
CoordinateChartData["Polar", "InverseMetric", {r,θ}]

vf=CoordinateChartData["Polar", "VolumeFactor", {r,θ}]

(∫_0^R)(∫_0^(2π))vf \[DifferentialD]θ\[DifferentialD]r

CoordinateChartData["Polar","StandardCoordinateNames", {r,θ}]

% // InputForm

ToExpression /@ % // InputForm

test = CoordinateChartData[{"Polar",2}, "CoordinateRangeAssumptions"]

test[{3, π/2}]  (* gueltiger Punkt *)

test[{-3, π/2}]  (* ungueltiger Punkt *)

(* Verwendung der Metrik, Beispiel Zylinder-Koordinaten, die auf einer Helix verwendet werden koennen. 
Give the components of the (covariant) metric as a matrix: *)

CoordinateChartData[{"Cylindrical",3},"Metric"][{r,θ,z}]

(* By particularizing to a curve,the metric can be used to compute the differential arc length *)

metric[t_]=CoordinateChartData[{"Cylindrical",3},"Metric"][{r[t],θ[t],z[t]}]

helix[t_] = {a,b t,c t}

helix'[t] . metric[t].helix'[t] /. r[t]-> a

(* Allgemeine Anwendung:  
A function to compute the differential arc length of a curve in a particular coordinate system: *)
ds[curve_List,t_,chart_] := Module[{metric, tangent},
metric = CoordinateChartData[chart, "Metric", curve];
tangent = D[curve,t];
Sqrt[tangent . metric . tangent] \[DifferentialD]t
]
(* The differential arc length of a general curve in polar coordinates: *)

ds[{r[t],θ[t]},t, "Polar"]

(* The differential arc length of a helix expressed in cylindrical coordinates: *)
ds[{R, u, u}, u,{"Cylindrical",3}]

(* This can now be integrated: *)

s[t_]:=(∫_0^t)(Sqrt[1+(R^2)]) \[DifferentialD]u

s[t]   (* Die wahre Bogenlaenge ist somit *)

(* Analoge 3-dimensionale Transformation *)

CoordinateTransformData["Cartesian"->"Spherical","Mapping", {x,y,z}]

CoordinateTransformData["Spherical"->"Cartesian","Mapping", {r,θ,φ}]

CoordinateTransformData["Spherical"->"Cartesian","Mapping", {r,θ,φ}]
CoordinateTransformData["Cartesian"->"Polar", "MappingJacobian", {x,y}]
CoordinateTransformData["Spherical"->"Cartesian","Mapping", {r,θ,φ}]

vf=CoordinateChartData[{"Spherical",3}, "VolumeFactor", {r,θ,φ}]

(∫_0^R)(∫_0^π)(∫_0^(2π))vf  \[DifferentialD]φ\[DifferentialD]θ\[DifferentialD]r

(* Allgemeine Uebersicht zu Koordinatensystemen in der Ebene *)

CoordinateChartData[{ All, 2}]

(* Allgemeine Uebersicht zu Koordinatensystemen im 3-dimensionalen Euklidischen Raum *)

CoordinateChartData[{ All, 3}]

(* Ein gegebenes Vektorfeld in andere Koordinaten umrechnen *)

TransformedField[t,f,{(Subscript[x, 1]),(Subscript[x, 2]),…,(Subscript[x, n])}->{(Subscript[y, 1]),(Subscript[y, 2]),…,(Subscript[y, n])}]
(*
uses the coordinate transformation t to transform the scalar,vector, or tensor field f from coordinates (Subscript[x, i]) to (Subscript[y, i ]). *)

(* Beispiel: An electric dipole of dipole moment p located at the origin and aligned with the z axis has the following electric potential in spherical coordinates:

Vs = (p  Cos[θ]) / r^2

Plot3D[((Cos[θ])/(r^2)),{r,-1.1,1.1},{θ,-Pi/2,Pi/2},PlotRange->{0,10},AxesLabel->{r,θ,Vs /. p-> 1}]

Compute the corresponding expression in Cartesian coordinates:

Vc=TransformedField[ "Spherical"->"Cartesian",Vs, {r,θ,φ} ->{x,y,z}]

Derive the dipole electric field in spherical coordinates:
!! Der Gradient kann einfach als Grad angesetzt werden, wenn man noch das verwendete Koordinatensystem angibt !!

Es = -Grad[Vs, {r,θ,φ}, "Spherical"]

Transform this expression to Cartesian coordinates:

Ec=TransformedField["Spherical"->"Cartesian",Es,{r,θ,φ} ->{x,y,z}]

The same expression is obtained by differentiating the Cartesian potential function:

Ec==-Grad[Vc,{x,y,z}]//Simplify

Plot the lines of force in the  yz  plane:

StreamPlot[Rest[Ec /. {p->1, x->0}]//Evaluate, {y, -1,1},{z, -1,1},FrameLabel->{y,z}]

(* Rest verwendet die erste Komponente nicht; damit sind wir fuer Ec wirklich in der yz - Ebene *)

(* This transforms a rank-2 tensor 
from Cartesian to polar coordinates.  *)

mat = {{x ^2 + y^2,0}, {0,x^2y^2}}

TransformedField["Cartesian"->"Polar",mat, {x,y}->{r,θ}] //Simplify

(* man beachte, dass dies keine Diagonalmatrix mehr ist ! *)

Using Map,
it is possible to transform the matrix as a list of two vectors or as a matrix of four scalar fields. 
The results are quite different in each case.

Map[TransformedField[ "Cartesian"->"Polar",#, {x,y}->{r,θ}]&,mat]//Expand
TrigReduce[%]

(* hier versagt bei der Vereinfachung auch TrigReduce: 
-(r^2) ((Cos[θ])^2) Sin[θ]-(r^2) ((Sin[θ])^(3      ))= -(r^2) Sin[θ]
 (r^4) ((Cos[θ])^2) ((Sin[θ])^3) = (r^4) Sin[θ] (1/8) (1-Cos[4 θ]) 
(r^4) ((Cos[θ])^3) ((Sin[θ])^2) = (r^4) Cos[θ] (1/8) (1-Cos[4 θ]) 
 mit *)
TrigReduce[((Cos[θ])^2) ((Sin[θ])^2)]

Map[TransformedField[ "Cartesian"->"Polar",#, {x,y}->{r,θ}]&,mat,{2}]//Simplify

(* Dies bekommt man also, wenn man direkt komponentenweise in mat die 
Koordinatentransformation einsetzt. *)