2d graphics using polar coordinates

113 views
Skip to first unread message

ablondin

unread,
Sep 27, 2009, 6:02:45 PM9/27/09
to sage-support
Hello everybody,
I think I'm not looking correctly, but is there any way to use the
circle, line, polygon functions to draw 2d graphics using polar
coordinates ? I would like to draw things on the unit circle and if it
possible, to avoid writing line([(0.9*cos(theta), 0.9*sin(theta),
(1.1*cos(theta), 1.1*sin(theta)]) to draw a small segment on the
circle at angle theta.
Thanks for you help !
Alexandre Blondin Massé

ablondin

unread,
Sep 27, 2009, 6:07:12 PM9/27/09
to sage-support
I forgot to mention that in polar coordinates, it would be something
like line([(0.9,theta), (1.1, theta)]) which is more convenient.
Alexandre Blondin Massé

Marshall Hampton

unread,
Sep 27, 2009, 10:48:33 PM9/27/09
to sage-support
I don't think there is such a thing in Sage right now, but its not
hard to make something like that. For example:

def pline(rt_list):
'''
Returns line segments passing through the given list of points
in polar coordinates.
'''
cart_list = [[x[0]*cos(x[1]),x[0]*sin(x[1])] for x in rt_list]
return line(cart_list)

I'm not sure what a good name for that would be, "pline" is pretty
bad.

-Marshall Hampton

On Sep 27, 5:07 pm, ablondin <alexandre.blondin.ma...@gmail.com>
wrote:

kcrisman

unread,
Sep 28, 2009, 8:25:24 AM9/28/09
to sage-support


On Sep 27, 10:48 pm, Marshall Hampton <hampto...@gmail.com> wrote:
> I don't think there is such a thing in Sage right now, but its not
> hard to make something like that.  For example:
>
> def pline(rt_list):
>     '''
>     Returns line segments passing through the given list of points
>     in polar coordinates.
>     '''
>     cart_list = [[x[0]*cos(x[1]),x[0]*sin(x[1])] for x in rt_list]
>     return line(cart_list)
>
> I'm not sure what a good name for that would be, "pline" is pretty
> bad.
>

Mathematica has something like this, or at least to plot polar points,
called ListPolarPlot. Something similar and with line support would
not be difficult, I think Marshall is right.

We are tracking this request here:
http://trac.sagemath.org/sage_trac/ticket/7050

- kcrisman

Jason Grout

unread,
Sep 28, 2009, 9:28:03 AM9/28/09
to sage-s...@googlegroups.com
kcrisman wrote:
>
>
> On Sep 27, 10:48 pm, Marshall Hampton <hampto...@gmail.com> wrote:
>> I don't think there is such a thing in Sage right now, but its not
>> hard to make something like that. For example:
>>
>> def pline(rt_list):
>> '''
>> Returns line segments passing through the given list of points
>> in polar coordinates.
>> '''
>> cart_list = [[x[0]*cos(x[1]),x[0]*sin(x[1])] for x in rt_list]
>> return line(cart_list)
>>
>> I'm not sure what a good name for that would be, "pline" is pretty
>> bad.
>>
>
> Mathematica has something like this, or at least to plot polar points,
> called ListPolarPlot. Something similar and with line support would
> not be difficult, I think Marshall is right.
>
> We are tracking this request here:
> http://trac.sagemath.org/sage_trac/ticket/7050
\

Please note that matplotlib already addresses these issues. See, for
example, this discussion:

http://www.mail-archive.com/matplotl...@lists.sourceforge.net/msg04785.html

We just have to change our polar plots to use the matplotlib polar
plotting mechanism. That's something I've been meaning to do anyway,
especially now that we use the matplotlib axes instead of our own. I
probably won't get to it in the near future, though. Someone else is
more than welcome to do it.

Basically, right now, our "polar plots" are just normal plots with the
coordinates undergoing the polar transformation on each point. I think
it might be good to change this so that our polar plots actually use the
polar projection to give matplotlib polar plots. See


Examples of matplotlib polar plots:

http://matplotlib.sourceforge.net/examples/pylab_examples/polar_bar.html
http://matplotlib.sourceforge.net/examples/pylab_examples/polar_demo.html
http://matplotlib.sourceforge.net/examples/pylab_examples/polar_scatter.html

or more exciting stuff that is currently in matplotlib and being refined:

http://matplotlib.sourceforge.net/examples/axes_grid/demo_curvelinear_grid.html

http://matplotlib.sourceforge.net/examples/axes_grid/demo_floating_axis.html

Thanks,

Jason


--
Jason Grout

Reply all
Reply to author
Forward
0 new messages