# 3d polar plot

I have to do a 3d polar plot. i.e. I have to make a 3d plot by rotating a 2d polar plot along the vertical axis.

The polar plot is of the form r=f(theta). But the polar_plot function in sage gives me only 2d plot. How do I get a 3D version of it?

I tried spherical_plot but it is not giving me the plot which I expect to be equivalent to the revolution surface I get from rotating the 2d polar plot along vertical axis.

Example:

show(polar_plot(sin(2*theta),theta,0,2*pi))


I wanted to plot this sin(2*theta) function as a 3d plot, by revolving it around by it's vertical axis. But the command

spherical_plot3d(sin(2*theta),(theta,0,2*pi),(x,0,pi))


Is not giving me that. It is giving me another shape instead.

Or Another Example: polar_plot of cos(theta)

I want to do a 3d polar plot of this to get a doughnut shape

I shall also give another example with pictures. The following plot is what I wanted using spherical3d plot But in sage, giving the same command is giving me this plot instead. What command should I give in sage to get a plot like the one we get from Mathematica?

edit retag close merge delete

Sort by » oldest newest most voted

I figured out the problem. In sage spherical 3d plot, I had to give phi component first and theta component second. The syntax is exactly opposite of Mathematica syntax.

spherical_plot3d(1+2cos(2x),(y,0,2*pi),(x,0,pi),aspect_ratio=1).show()

This gave me the correct plot I wanted. I hope this post will be helpful if anybody else also gets bugged by this reverse input format of spherical_plot3d function.

Thanks to everyone for answers they provided...

more

Glad you figured it out! Is the documentation for spherical_plot3d incorrect? Keep in mind that although Sage often uses Mma or another program (Magma, etc.) for inspiration for commands, we don't always feel compelled to give identical syntax (like Octave does with Matlab). At the same time, if we'd caught this right away, we probably would have done so just for ease of use! Now it would change a lot of people's code, so even if the doc is wrong we'd probably just fix the doc, not the actual code.

1

No, the syntax for spherical_plot3d is not incorrect, and we gave great thought to the syntax, taking into account how mathematica and other systems do spherical coordinates. There are lots of conventions for how spherical coordinates are specified, and in fact, I think a strong case could be made that Mathematica's syntax is backwards for mathematics (it's not even consistent with Wolfram Mathworld). See my answer below for an explanation of the issue.

In different disciplines, phi and theta mean different things. In Sage, we use "azimuth", "elevation", and "inclination", rather than "phi" and "theta". See mathworld for many ways in which spherical coordinates are phrased in different disciplines.

In Sage, you can define the coordinates however you choose. The spherical_plot3d function adopts the convention that the first argument is the azimuth angle and the second angle is the inclination angle (or "polar angle"). This is consistent with calculus textbooks, for example, and provides a natural extension of the polar plot commands (where the single parameter is the azimuth angle).

Note that in mathematica, the SphericalPlot3d "phi" corresponds to the PolarPlot "theta" (that's the azimuth angle) and the SphericalPlot3d "theta" is the inclination angle (which in lots of calculus textbooks is called "phi"). So according to many calculus textbook, and according to the Wolfram Mathworld website, Mathematica has the names backwards (i.e., Mathematica uses theta for inclination angle and phi for azimuth angle, whereas typical mathematical convention is to use theta for azimuth angle and phi for inclination angle).

Read the documentation to Spherical to see how to change the coordinate system to match Mathematica's order. For example, try this:

T = Spherical('radius', ['inclination', 'azimuth']) # matches Mathematica ordering
var('theta,phi')
plot3d(1+2*cos(2*theta), (theta, 0, pi), (phi, 0, 2*pi), transformation=T, aspect_ratio=1)


Note that Sage has many other transformations built in, and lets you define your own transformations however you want. See the examples in the plot3d documentation

more

Maybe it would be good to add a note to this effect in the spherical_plot3d documentation so that people transferring from Mathematica understand this issue.

Thank you very much for explaining the syntax. I was not aware of this. As you suggested it will be nice if this point is added in the documentation. It took me lot of time to figure out that the problem in my plot was due to this difference.

One of the examples in the Wikipedia article for parametric surfaces gives the formula for parametrizing a surface of revolution. Following that example, here are the plots I produced with sage's parametric_plot3d function-- are these what you were hoping for?

sage: var('u,phi')
(u, phi)
sage: parametric_plot3d([u*cos(phi), u*sin(phi), sin(u)], (u, 0, 2*pi), (phi, 0, 2*pi), aspect_ratio=1) sage: parametric_plot3d([u*cos(phi), u*sin(phi), sqrt(1 - (u-2)^2)], (u, 0, 3), (phi, 0, 2*pi), aspect_ratio=1) more

My function which gives r is in terms of theta in polar coordinates. So the parametric_plot3d with parametrization you suggested is not giving what i wanted. I have added 2 plots of what I expected and what I got in sage in my question. I hope, they will make clear what plot precisely I want to generate.

You've tried spherical_plot3d, it looks like.

Have you tried cylindrical_plot3d? If you give a more explicit example of what you need, this could help as well.

more

I have added an example. cylindrical_plot3d seems to me not i want. I am not sure whether i gave spherical_plot3d coordinates correctly. I have posted example of the command i gave.

I have added pictorial example too. Is my question clear?