Re: Converting between Spherical and Cartesian coordinates
- To: mathgroup at smc.vnet.net
- Subject: [mg53336] Re: Converting between Spherical and Cartesian coordinates
- From: Alain Cochard <alain at geophysik.uni-muenchen.de>
- Date: Thu, 6 Jan 2005 22:00:37 -0500 (EST)
- References: <crg14d$bg8$1@smc.vnet.net> <crir73$s5k$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Alain Cochard writes:
> > I use spherical coordinates:
> >
> > In[1]:= << Calculus`VectorAnalysis` ;
> >
> > In[2]:= SetCoordinates[Spherical]
> >
> > Out[2]= Spherical[Rr, Ttheta, Pphi]
> >
> > and I convert:
> >
> > In[3]:= CoordinatesFromCartesian[{x,y,z}]
> >
> > 2 2 2 z
> > Out[3]= {Sqrt[x + y + z ], ArcCos[------------------], ArcTan[x, y]}
> > 2 2 2
> > Sqrt[x + y + z ]
> >
> > Now, if I use the expressions for x, y, and z, I expect to get back to
> > Rr, Ttheta, Pphi, but:
> >
> > In[4]:= FullSimplify[%3/.{
> > x->Rr Sin[Ttheta]Cos[Pphi],
> > y->Rr Sin[Ttheta]Sin[Pphi],
> > z->Rr Cos[Ttheta]},
> > Rr>=0 && 0 <= Ttheta <= Pi && -Pi < Pphi <= Pi]
> >
> > Out[4]= {Rr, Ttheta, ArcTan[Rr Cos[Pphi] Sin[Ttheta],
> >
> > > Rr Sin[Pphi] Sin[Ttheta]]}
> >
> >
> > Even if I remove the equalities from the assumptions, I am not quite
> > there:
> >
> > In[5]:= FullSimplify[%3/.{
> > x->Rr Sin[Ttheta]Cos[Pphi],
> > y->Rr Sin[Ttheta]Sin[Pphi],
> > z->Rr Cos[Ttheta]},
> > Rr>0 && 0 < Ttheta < Pi && -Pi < Pphi < Pi]
> >
> > Out[5]= {Rr, Ttheta, ArcTan[Cos[Pphi], Sin[Pphi]]}
> >
> > But I would have thought that for a given Pphi in (-Pi,Pi), there is a
> > unique value for ArcTan[Cos[Pphi], Sin[Pphi]], which is... Pphi. And
> > this seems to me consistent with the fact that a given (single) point
> > is unique, or, in other words, that to a given (perhaps
> > not-too-specific) {x,y,z} corresponds a unique {Rr, Ttheta, Pphi}, and
> > vice versa.
> >
> > What am I missing here?
> >
> > Thanks in advance,
> > AC
> >
>
Astanoff writes:
> Alain,
>
> Seems that it does simplify if Pphi (as a latitude) ranges
> from -Pi/2 to Pi/2 and if you don't allow equalities in coordinate
> ranges :
Yes, of course, and ...
> In[1]:=<<Calculus`VectorAnalysis`
>
> In[2]:=SetCoordinates[Spherical]
> Out[2]=Spherical[Rr,Ttheta,Pphi]
>
> In[3]:=
> Unprotect[CoordinateRanges];
> CoordinateRanges[ ]={0<Rr<Infinity, 0<Ttheta<Pi, -Pi/2<Pphi<Pi/2};
> Protect[CoordinateRanges];
>
> In[6]:=sph=CoordinatesFromCartesian[{x,y,z}]
> Out[6]={Sqrt[x^2 + y^2 + z^2], ArcCos[z/Sqrt[x^2 + y^2 + z^2]],
> ArcTan[x, y]}
>
> In[7]:=
> car=sph /. Thread[{x,y,z} -> CoordinatesToCartesian[{Rr,Ttheta,Pphi}]]
> Out[7]=
> {Sqrt[Rr^2*Cos[Ttheta]^2 + Rr^2*Cos[Pphi]^2*Sin[Ttheta]^2 +
> Rr^2*Sin[Pphi]^2*Sin[Ttheta]^2],
> ArcCos[(Rr*Cos[Ttheta])/Sqrt[Rr^2*Cos[Ttheta]^2 +
> Rr^2*Cos[Pphi]^2*Sin[Ttheta]^2 +
> Rr^2*Sin[Pphi]^2*Sin[Ttheta]^2]],
> ArcTan[Rr*Cos[Pphi]*Sin[Ttheta], Rr*Sin[Pphi]*Sin[Ttheta]]}
>
> In[8]:=car // Simplify[#,CoordinateRanges[ ]]&
> Out[8]={Rr,Ttheta,Pphi}
... and there is not even the need to redefine the range as you do
above:
In[1]:= << Calculus`VectorAnalysis`;
<< Calculus`VectorAnalysis`;
In[2]:= SetCoordinates[Spherical]
Out[2]= Spherical[Rr, Ttheta, Pphi]
In[3]:= CoordinatesFromCartesian[{x,y,z}]
2 2 2 z
Out[3]= {Sqrt[x + y + z ], ArcCos[------------------], ArcTan[x, y]}
2 2 2
Sqrt[x + y + z ]
In[4]:= FullSimplify[%3/.{
x->Rr Sin[Ttheta]Cos[Pphi],
y->Rr Sin[Ttheta]Sin[Pphi],
z->Rr Cos[Ttheta]},
Rr>0 && 0 < Ttheta < Pi && -Pi/2 < Pphi < Pi/2]
Out[4]= {Rr, Ttheta, Pphi}
but with this restricted range one does not cover the whole space. So
my initial question remains...
Thanks anyway,
Alain