alan
(Alan Smith)
November 13, 2015, 12:34am
1
It’s a learning curve …
I want to plot simultaneous functions using cylindrical coords, like
ContourPlot3D[ r^2 + z^2 - 1 == 0, {r, -5, 5}, {\[Phi] , 0, 2 \[Pi] }, {z, -1, 1}]
looks weird, thinks its still in Cartesian, tried to change to cylindrical without much luck.
The real objective is
ContourPlot3D[{r^2 + z^2 - 1 == 0}, {r = Sin[\[Phi]]}, {r, -5, 5}, {\[Phi], 0, 2 \[Pi]}, {z, -3, 3}]
Would appreciate the help, thanks.
niktsak23
(nik tsak)
November 13, 2015, 10:45pm
2
I’m not sure what you’re trying to do there but I’d guess that if you have in mind a discrete range of values for Phi eg
phi = {0,Pi/6,Pi/4,Pi/3,Pi/2,Pi,2Pi/3,3Pi/4,5Pi/6,Pi,7Pi/6,5Pi/4,4Pi/3,2Pi}
then you’d probably be able to apply appropriate transformations to the bounds of the variables inside
ContourPlot
What I have in mind is something like
rLoBound[x_,phi_]:=(appropriate calcs)
rHiBound[x_,phi_]:=(appropriate calcs)
zLoBound[x_,phi_]:=(appropriate calcs)
zHiBound[x_,phi_]:=(appropriate calcs)
ContourPlot3D[{r^2 + z^2 - 1 == 0}, {r, rLoBound[-5,#], rHiBound[5,#]}, {z, zLoBound[-3,#], zHiBound[3,#]}]&/@phi
alan
(Alan Smith)
November 15, 2015, 9:54pm
3
That’s more complicated than I expected. Surely Mathematica can directly use cylindrical (or polar) cords?
The documentation says to use SetCoordinates[Cylindrical] - but I don’t get the expected output from that, which should be Cylindrical[Rr, Ttheta, Zz] - and we should in theory then be able to directly do what I want …
But I tried the above, then ContourPlot3D[ Rr^2 + Zz^2 - 1 == 0, {Rr, -5, 5}, {Ttheta, 0, 2 [Pi]}, {Zz, -1, 1}] - and got the same warped ‘thing’.
Is there a bug with SetCoordinates perhaps?
22padrinos
(Luis Ledesma)
November 16, 2015, 12:02am
4
I think the syntax is wrong , I do not know you’re trying to get , but I did this and got the following
sukrause
(Udo Krause)
November 16, 2015, 9:26pm
5
You want to plot a sphere using cylindrical co-ordinates? x= r\cos(\phi), y=r \sin(\phi), z = z , so x^2+y^2=r^2 and your equation defines a sphere circle in the plane at height z . If that really must be done, then r grows from 0 (at z=-1 ) to 1 (at z = 0) and decreases back to 0 (at z=1 ) and of course this is given by r=\sqrt(1-z^2) . So one types (because ParametricPlot3D[] draws into an euclidean orthonormal co-ordiante system) just
ParametricPlot3D[{Sqrt[1 - z^2] Cos[\[Phi]], Sqrt[1 - z^2] Sin[\[Phi]], z}, {z, -1, 1}, {\[Phi], 0, 2 \[Pi]}]
to see as expected
alan
(Alan Smith)
November 16, 2015, 10:21pm
6
Hi - one of the 2 eqtns I want to plot is {r = Sin[[Phi]]}
But for coords - it’s more that the other function I wish to plot simultaneously is a cylinder. So is the conclusion I would have to convert any cylindrical functions into Cartesian to plot them?
sghuisman
(Sander Huisman)
November 16, 2015, 10:43pm
7
You can easily from and to coordinate using:
Thread[{r, \[Theta], z} -> CoordinateTransformData["Cartesian" -> "Cylindrical", "Mapping", {x, y, z}]]
sghuisman
(Sander Huisman)
November 16, 2015, 10:54pm
8
SetCoordinates will not affect plotting, only some vector analysis functions., and the SetCoordinates-function is now kinda deprecated because all the vector analysis functionality is now built-in to the core.
alan
(Alan Smith)
November 17, 2015, 2:18am
9
Does that just tell me what substitutions to make, or should it allow me to use cylindrical cords directly?
Didn’t seem to, so I tried
ContourPlot3D[ x^2 + y^2 + z^2 - 1 == 0, {x, -2, 2}, {y, -2, 2 }, {z, -1, 1}]
but this is not a cylinder …
Nice work, but you can try something along these lines:
With[{r = Sqrt[x^2 + y^2], \[Phi] = ArcTan[x, y]},
ContourPlot3D[{r^2 + z^2 - 1 == 0, r == Sin[\[Phi]]}, {x, -1,
1}, {y, -1, 1}, {z, -3, 3}]]
alan
(Alan Smith)
November 17, 2015, 8:26pm
11
That worked very nicely, thank you. I also added axes - makes it easy to keep track when rotating the image…
I also wanted Opacity, but despite being in the documentation, the following failed :
With[{r = Sqrt[x^2 + y^2], \[Phi] = ArcTan[x, y]},
ContourPlot3D[{r^2 + z^2 - 1 == 0, r == Sin[\[Phi]]}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
PlotStyle -> Opacity[0.5],
AxesLabel -> {"x-axis", "y-axis", "z-axis"},
LabelStyle -> Directive[Bold, Medium, Red]]]
'Unknown option name has been used" - any idas how to make the functions partly opaque?
Thanks
sghuisman
(Sander Huisman)
November 17, 2015, 9:21pm
12
ContourStyle instead of PlotStyle…should work…
alan
(Alan Smith)
November 22, 2015, 9:10pm
13
Thanks Sander, that is nice. ( Delay because I had lots of hassles upgrading to win 10, eventually had to rebuild my PC)
Is there a command to Plot this without the contour lines? I tried replacing with GraphPlot3D but this wont accept some of the options …
sghuisman
(Sander Huisman)
November 22, 2015, 9:14pm
14
add MeshFunctions -> {} as an option.
alan
(Alan Smith)
November 23, 2015, 3:35am
15
Awesome.
Sorry if I’m being a nuisance, but do you perhaps know how to add the gradient for each function to this plot?
I tried
With[{r = Sqrt[x^2 + y^2], [Phi] = ArcTan[x, y]},
ContourPlot3D[{r^2 + z^2 - 1 == 0, r == Sin[[Phi]]}, {x, -1,
1}, {y, -1, 1}, {z, -1, 1},
Grad[{r^2 + z^2 - 1 == 0, r == Sin[[Phi]]}, {x, -1, 1}, {y, -1, 1}],
ContourStyle → Opacity[0.3],
AxesLabel → {“x-axis”, “y-axis”, “z-axis”},
MeshFunctions → {},
LabelStyle → Directive[Bold, Medium, Red]]]
ie just adding in the grad function with it’s mandatory options …
but I think it swore at me
Perhaps something along these lines:
With[{r = Sqrt[x^2 + y^2], \[Phi] = ArcTan[x, y]},
Show[ContourPlot3D[
Evaluate[{r^2 + z^2 - 1 == 0, r == Simplify[Sin[\[Phi]]]}], {x, -1,
1}, {y, -1, 1}, {z, -1, 1}, ContourStyle -> Opacity[0.3],
AxesLabel -> {"x-axis", "y-axis", "z-axis"}, MeshFunctions -> {},
LabelStyle -> Directive[Bold, Medium, Red]],
VectorPlot3D[{Grad[r^2 + z^2 - 1, {x, y, z}],
Grad[r - Simplify@Sin[\[Phi]], {x, y, z}]}, {x, -1, 1}, {y, -1,
1}, {z, -1, 1}]]]