polar coordinates?

Oscar Benjamin oscar.j.benjamin at gmail.com
Sun Dec 9 13:48:33 EST 2018


On Sun, 9 Dec 2018 at 16:37, Brian Christiansen
<brian_christians at hotmail.com> wrote:
>
> I have been messing with a program that is inspried by a video on
> youtube that is about the vizualization of pi.  I might make a post
> about that program someday, but I want to talk about something else.
> One of the ways of visualizing it is to put dots corresponding to each
> digits in a spiral pattern, in a color corresponding to what the digit
> is. I think this would be easiest, at least in the initial calculation
> of the point would be to use polar coordinates.
>
> For example, if I were to use a very simple archimedian spiral, r = 0 +
> (1 x theta), the "first 4" points, if theta increases by 1 degree
> (2pi/360 radians), are (0,0) (2pi/360 "units",2pi/360"radians")
> (4pi/360, 4pi/360) (6pi/360,6pi/360).
>
> The problem is that python (more specifically tkinter or graphics.py
> file that I downloaded) can't use polar coordinates directly to plot
> points (or at least I don't think they can). The polar coordinates have
> to be converted to cartesian coordinates, then converted to the
> coordinate system that a computer uses to actually plot points on the
> screen.

Hi Brian,

I don't think anything exists (apart from matplotlib) to do this for you:
https://matplotlib.org/examples/pylab_examples/polar_demo.html

Converting from polar to Cartesian coordinates is easy enough though.
For your case if xc_p, yc_p are the pixel coordinates of the centre of
your window and rq and thetaq are the polar coordinates for point q
then

    from math import sin, cos
    xq_p = xc_p + r * cos(theta) * pix_scale
    yq_p = yc_p - r * sin(theta) * pix_scale

gives the pixel coordinates for q. The parameter pix_scale is the
number of pixels that corresponds to a distance of 1 in your polar
coordinate system. You might choose this parameter based on the
height/width in pixels of the window. Depending on what you're doing
you may need to convert xq_p and yq_p to int rounding in some way.

--
Oscar


More information about the Python-list mailing list