Ask Your Question
3

3d polar plot

asked 2011-09-19 17:01:43 +0100

indiajoe gravatar image

updated 2011-09-20 02:48:15 +0100

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

image description

But in sage, giving the same command is giving me this plot instead.

image description

What command should I give in sage to get a plot like the one we get from Mathematica?

edit retag flag offensive close merge delete

Comments

I have added example.

indiajoe gravatar imageindiajoe ( 2011-09-19 17:49:03 +0100 )edit

4 Answers

Sort by ยป oldest newest most voted
3

answered 2011-09-20 04:11:50 +0100

indiajoe gravatar image

updated 2023-08-07 20:03:23 +0100

dan_fulea gravatar image

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 + 2*cos(2*x), (y,0,2*pi), (x,0,pi), aspect_ratio=1).show()

This gave me the correct plot I wanted.

image description

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...

edit flag offensive delete link more

Comments

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.

kcrisman gravatar imagekcrisman ( 2011-09-20 10:44:56 +0100 )edit
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.

Jason Grout gravatar imageJason Grout ( 2011-09-20 11:26:55 +0100 )edit
1

i've edited the accepted one-liner so that that one line

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

appears correctly displayed. (Formerly, there was a >-marked indent, and the first two stars were leading to an italic mark-up of the in between characters, while the third one remained "unmatched" and thus shown, it was also an occasion to upvote...

dan_fulea gravatar imagedan_fulea ( 2023-08-07 20:05:31 +0100 )edit
3

answered 2011-09-20 11:23:27 +0100

Jason Grout gravatar image

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

edit flag offensive delete link more

Comments

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.

Jason Grout gravatar imageJason Grout ( 2011-09-20 11:30:45 +0100 )edit

Thanks for volunteering!

kcrisman gravatar imagekcrisman ( 2011-09-20 12:58:58 +0100 )edit

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.

indiajoe gravatar imageindiajoe ( 2011-09-20 14:46:28 +0100 )edit
0

answered 2011-09-19 22:48:50 +0100

niles gravatar image

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)

sin revolution

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

image description

edit flag offensive delete link more

Comments

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.

indiajoe gravatar imageindiajoe ( 2011-09-20 02:11:54 +0100 )edit
0

answered 2011-09-19 17:10:33 +0100

kcrisman gravatar image

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.

edit flag offensive delete link more

Comments

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.

indiajoe gravatar imageindiajoe ( 2011-09-19 17:23:24 +0100 )edit

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

indiajoe gravatar imageindiajoe ( 2011-09-20 02:12:39 +0100 )edit

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: 2011-09-19 17:01:43 +0100

Seen: 4,043 times

Last updated: Aug 07 '23