some 3d plot examples in SAGE

258 views
Skip to first unread message

David Joyner

unread,
Jan 18, 2008, 9:24:25 AM1/18/08
to sage-...@googlegroups.com
Hi:

Here are a few examples which I think are interesting.

If anyone can figure out a way to plot a cardioid,
http://mathworld.wolfram.com/HeartSurface.html,
in SAGE, I'd be very interested.

- David Joyner

#M\"obius strip:
sage: u,v = var("u,v")
sage: p = parametric_plot3d([cos(u)*(1+v*cos(u/2)),
sin(u)*(1+v*cos(u/2)), 0.2*v*sin(u/2)], (u,0, 4*pi), (v,0,
0.3),plot_points=[50,50])

#twisted ribbon
sage: p = parametric_plot3d([3*sin(u)*cos(v), 3*sin(u)*sin(v),
cos(v)], (u,0, 2*pi), (v, 0, pi),plot_points=[50,50])

#ellipsoid (automatically rescaled axes make it look spherical)
sage: p = parametric_plot3d([3*sin(u)*cos(v), 2*sin(u)*sin(v),
cos(u)], (u,0, 2*pi), (v, 0, 2*pi),plot_points=[50,50])

#cone
sage: p = parametric_plot3d([u*cos(v), u*sin(v), u], (u, -1, 1), (v,
0, 2*pi), plot_points=[50,50])

#paraboloid
sage: p = parametric_plot3d([u*cos(v), u*sin(v), u^2], (u, 0, 1), (v,
0, 2*pi), plot_points=[50,50])

#hyperboloid
sage: p = plot3d(u^2-v^2, (u, -1, 1), (v, -1, 1), plot_points=[50,50])

#weird looking surface - like a M\"obius band but also an O
sage: p = parametric_plot3d([sin(u)*cos(u)*log(u^2)*sin(v),
(u^2)^(1/6)*(cos(u)^2)^(1/4)*cos(v), sin(v)], (u, -1, 1), (v, -pi,
pi), plot_points=[50,50])


#a heart, but not a cardioid (for my wife)
sage: p1 = parametric_plot3d([sin(u)*cos(u)*log(u^2)*v*(1-v)/2,
((u^6)^(1/20)*(cos(u)^2)^(1/4)-1/2)*v*(1-v), v^(0.5)], (u, 0.001, 1),
(v, 0, 1), plot_points=[90,90])
sage: p2 = parametric_plot3d([-sin(u)*cos(u)*log(u^2)*v*(1-v)/2,
((u^6)^(1/20)*(cos(u)^2)^(1/4)-1/2)*v*(1-v), v^(0.5)], (u, 0.001, 1),
(v, 0, 1), plot_points=[90,90])
sage: show(p1+p2, frame=False)

William Stein

unread,
Jan 18, 2008, 10:06:50 AM1/18/08
to sage-...@googlegroups.com
On Jan 18, 2008 6:24 AM, David Joyner <wdjo...@gmail.com> wrote:
>
> Hi:
>
> Here are a few examples which I think are interesting.
>
> If anyone can figure out a way to plot a cardioid,
> http://mathworld.wolfram.com/HeartSurface.html,
> in SAGE, I'd be very interested.
>
> - David Joyner
>
> #M\"obius strip:
> sage: u,v = var("u,v")
> sage: p = parametric_plot3d([cos(u)*(1+v*cos(u/2)),
> sin(u)*(1+v*cos(u/2)), 0.2*v*sin(u/2)], (u,0, 4*pi), (v,0,
> 0.3),plot_points=[50,50])
>
> #twisted ribbon
> sage: p = parametric_plot3d([3*sin(u)*cos(v), 3*sin(u)*sin(v),
> cos(v)], (u,0, 2*pi), (v, 0, pi),plot_points=[50,50])
>
> #ellipsoid (automatically rescaled axes make it look spherical)
> sage: p = parametric_plot3d([3*sin(u)*cos(v), 2*sin(u)*sin(v),
> cos(u)], (u,0, 2*pi), (v, 0, 2*pi),plot_points=[50,50])

Use the aspect_ratio option:

sage: var('u,v')
sage: parametric_plot3d([3*sin(u)*cos(v), 2*sin(u)*sin(v), cos(u)],
(u,0, 2*pi), (v, 0, 2*pi),plot_points=[50,50], aspect_ratio=[1,1,1])

I've attached a Sage worksheet that has all the plots in this email rendered,
but with a few tweeks to make some of them work right or actually work.

Thanks!

I'll be adding this to the examples section of parametric_plot3d.

-- William

>
> #cone
> sage: p = parametric_plot3d([u*cos(v), u*sin(v), u], (u, -1, 1), (v,
> 0, 2*pi), plot_points=[50,50])
>
> #paraboloid
> sage: p = parametric_plot3d([u*cos(v), u*sin(v), u^2], (u, 0, 1), (v,
> 0, 2*pi), plot_points=[50,50])
>
> #hyperboloid
> sage: p = plot3d(u^2-v^2, (u, -1, 1), (v, -1, 1), plot_points=[50,50])
>
> #weird looking surface - like a M\"obius band but also an O
> sage: p = parametric_plot3d([sin(u)*cos(u)*log(u^2)*sin(v),
> (u^2)^(1/6)*(cos(u)^2)^(1/4)*cos(v), sin(v)], (u, -1, 1), (v, -pi,
> pi), plot_points=[50,50])
>
>
> #a heart, but not a cardioid (for my wife)
> sage: p1 = parametric_plot3d([sin(u)*cos(u)*log(u^2)*v*(1-v)/2,
> ((u^6)^(1/20)*(cos(u)^2)^(1/4)-1/2)*v*(1-v), v^(0.5)], (u, 0.001, 1),
> (v, 0, 1), plot_points=[90,90])
> sage: p2 = parametric_plot3d([-sin(u)*cos(u)*log(u^2)*v*(1-v)/2,
> ((u^6)^(1/20)*(cos(u)^2)^(1/4)-1/2)*v*(1-v), v^(0.5)], (u, 0.001, 1),
> (v, 0, 1), plot_points=[90,90])
> sage: show(p1+p2, frame=False)
>
> >
>

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

3d_parametric_plots____examples.sws

Hector Villafuerte

unread,
Jan 18, 2008, 10:29:18 AM1/18/08
to sage-...@googlegroups.com
Nice plots, thanks David!
About the cardiod, I gave it a try and started with this:

var('t')
a = 1
fx = a*cos(t)*(1-cos(t))
fy = a*sin(t)*(1-cos(t))*exp(-0.5*t)
f1 = (fx, fy)
parametric_plot(f1, 0, pi)

which then extended to this:

var('t v')
a = 1
fx = a*cos(t)*(1-cos(t))
fy = a*sin(t)*(1-cos(t))*exp(-0.5*t)*cos(v)
fz = a*sin(t)*(1-cos(t))*exp(-0.5*t)*sin(v)
f = (fx, fy, fz)
parametric_plot3d(f, (t,0,pi), (v,0,2*pi), rgbcolor='red')

Will your wife settle for an apple instead? :)
--
Hector

Jurgis Pralgauskis

unread,
Jan 18, 2008, 11:03:41 AM1/18/08
to sage-...@googlegroups.com
there are about 50 (if not more) surface examples in
http://k3dsurf.sourceforge.net/

I mean, sage examples can borrow formulas :)

--
Jurgis Pralgauskis
omni: 8-616 77613; teledema: 8-657 65656;
jabber: jur...@akl.lt; skype: dz0rdzas;

Don't worry, be happy :) and make things better ;)

David Joyner

unread,
Jan 18, 2008, 11:21:37 AM1/18/08
to sage-...@googlegroups.com
On Jan 18, 2008 10:29 AM, Hector Villafuerte <hect...@gmail.com> wrote:
>
> Nice plots, thanks David!
> About the cardiod, I gave it a try and started with this:
>
> var('t')
> a = 1
> fx = a*cos(t)*(1-cos(t))
> fy = a*sin(t)*(1-cos(t))*exp(-0.5*t)
> f1 = (fx, fy)
> parametric_plot(f1, 0, pi)
>
> which then extended to this:
>
> var('t v')
> a = 1
> fx = a*cos(t)*(1-cos(t))
> fy = a*sin(t)*(1-cos(t))*exp(-0.5*t)*cos(v)
> fz = a*sin(t)*(1-cos(t))*exp(-0.5*t)*sin(v)
> f = (fx, fy, fz)
> parametric_plot3d(f, (t,0,pi), (v,0,2*pi), rgbcolor='red')
>
> Will your wife settle for an apple instead? :)

Thanks, looks nice.

Very strangely, after running the commands that Jaap
posted in a separate email (smaller mayavi package), jmol now works
on my trusty/crusty/rusty old 64bit feisty fawn machine!!

David Joyner

unread,
Jan 18, 2008, 11:47:57 AM1/18/08
to sage-...@googlegroups.com
On Jan 18, 2008 11:03 AM, Jurgis Pralgauskis

<jurgis.pr...@gmail.com> wrote:
>
> there are about 50 (if not more) surface examples in
> http://k3dsurf.sourceforge.net/


Where? I can't find the docs and I'm having a hard time installing the
program....

Jurgis Pralgauskis

unread,
Jan 18, 2008, 12:41:24 PM1/18/08
to sage-...@googlegroups.com
might try asking at http://k3dsurf.s4.bizhat.com/
i attach k3dsurf source file, with these examples
ParisoMathObject.cpp

William Stein

unread,
Jan 18, 2008, 1:11:59 PM1/18/08
to sage-...@googlegroups.com
Hi David,

Another really nice source of 3d plot examples in the OS X program "Grapher"
that comes with every copy of OS X (in the Applications directory). It's quite
nice.

-- William

On Jan 18, 2008 9:41 AM, Jurgis Pralgauskis

Justin C. Walker

unread,
Jan 18, 2008, 1:33:07 PM1/18/08
to sage-...@googlegroups.com

On Jan 18, 2008, at 10:11 AM, William Stein wrote:

> Another really nice source of 3d plot examples in the OS X program
> "Grapher"
> that comes with every copy of OS X (in the Applications
> directory). It's quite
> nice.

It's actually in /Applications/Utilities (not completely obvious, at
least to me). It is a very nice program, descended from something
called Curvus Pro (which was an open-source program until someone
bought it :-}).

Justin

--
Justin C. Walker, Curmudgeon-At-Large
Director
Institute for the Enhancement of the Director's Income
--------
Here lies Lester Moore
Two bullets from a .44
No less, no more
--------


Pierre

unread,
Jan 26, 2008, 10:45:02 AM1/26/08
to sage-forum
hi everyone

i don't seem to be able to use the code for 3d plots that you
(everyone) suggest. I get the message:

"ReferenceError: jmolSetDocument is not defined"

in a popup window.

ant thoughts ?

Pierre

mabshoff

unread,
Jan 26, 2008, 10:48:58 AM1/26/08
to sage-forum


On Jan 26, 4:45 pm, Pierre <pierre.guil...@gmail.com> wrote:
> hi everyone

Hi Pierre,

> i don't seem to be able to use the code for 3d plots that you
> (everyone) suggest. I get the message:
>
> "ReferenceError: jmolSetDocument is not defined"
>
> in a popup window.
>
> ant thoughts ?

It doesn't ring a bell. Could you provide the following information:

a) Sage release
b) operating system
c) browser

If it fails with multiple combinations you should list those.

> Pierre

Cheers,

Michael

Pierre

unread,
Jan 26, 2008, 1:59:30 PM1/26/08
to sage-forum
> a) Sage release

SAGE Version 2.8.5, Release Date: 2007-09-21

> b) operating system

ubuntu gutsy

> c) browser

firefox 2.0.0.11

In fact I have just recently updated to gutsy and it screwed up
jsmath, i need to reinstall the fonts (so perhaps more side-effects
are to be expected). And i've also recently tried "sage -upgrade",
which i think went smoothly.

thanks
pierre

David Joyner

unread,
Jan 26, 2008, 2:14:45 PM1/26/08
to sage-...@googlegroups.com
On Jan 26, 2008 1:59 PM, Pierre <pierre....@gmail.com> wrote:
>
> > a) Sage release
>
> SAGE Version 2.8.5, Release Date: 2007-09-21

That is too old for the 3d graphics. Try "sage -upgrade" to
get the latest.

Pierre

unread,
Jan 27, 2008, 8:09:55 AM1/27/08
to sage-forum
> > SAGE Version 2.8.5, Release Date: 2007-09-21
>
> That is too old for the 3d graphics. Try "sage -upgrade" to
> get the latest.

i did that last week! i guess something went wrong (it took a VERY
long time btw). Besides, my sage directory contains a file "sage.
2.9.1.txt" and also "history.txt" which mentions sage 2.10...???

is there anything wrong with brutally deleting my sage folder and
downloading the latest ubuntu binaries ? (apart from the need to
download my favorite packages again -- there are only two i think).
Surely this beats having to wait 2 hours to recompile.

pierre

William Stein

unread,
Jan 27, 2008, 8:23:20 AM1/27/08
to sage-...@googlegroups.com
On Jan 27, 2008 5:09 AM, Pierre <pierre....@gmail.com> wrote:
>
> > > SAGE Version 2.8.5, Release Date: 2007-09-21
> >
> > That is too old for the 3d graphics. Try "sage -upgrade" to
> > get the latest.
>
> i did that last week! i guess something went wrong (it took a VERY
> long time btw).

Upgrading with "sage -upgrade" can take arbitrarily long, since it
builds all upgraded components from source. That particular upgrade,
in particular, involved changing the font encoding in Python (from
UCS2 to UCS4, for better support of system-wide Python libraries),
which entailed rebuilding a lot of Sage packages.

> Besides, my sage directory contains a file "sage.
> 2.9.1.txt"

It was a mistake that we didn't remove that.

> and also "history.txt" which mentions sage 2.10...???

Yes, becuse you upgraded to 2.10.
Try typing version() at the sage prompt.

> is there anything wrong with brutally deleting my sage folder and
> downloading the latest ubuntu binaries ?

No.

> (apart from the need to
> download my favorite packages again -- there are only two i think).
> Surely this beats having to wait 2 hours to recompile.

Yep.

-- William

Reply all
Reply to author
Forward
0 new messages