polar coordinates?
Brian Christiansen
brian_christians at hotmail.com
Wed Dec 19 17:32:17 EST 2018
On 12/19/18 12:19 PM, Dennis Lee Bieber wrote:
>
> I don't see anything in your code that makes any use of
> polar<>rectangular coordinate conversion -- which is what you were
> interested in when starting the thread. You appear to just be rastering a
> 15x15 rectangle (ie: the first 225 digits. If you really want to plot all
> the digits you provide, you should be looping over /them/, not some
> arbitrary X and Y coordinates.
>
>
I didn't say I yet had what I need to use polar coordinates for yet
working, or that I even yet had done anything past some planning in my
head. In the numberphile video I linked to, the 3rd (I think) way to
represent PI (the one professor Grimes says looks like the tiling in a
Roman bathhouse) and I think the 4th way (the one that is the other
guy's favorite I think) have only been designed a bit in my head so far.
I just think those 2 ways, which no code has been written for yet,
would be easier to do using polar coordinates. And yes, I know there
are ways that I could have used all 1000 digits of PI rather than just
49 of them.
>> pi1000 =
>> [3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0,2,8,
>> 8,4,1,9,7,1,6,9,3,9,9,3,7,5,1,0,
> <SNIP>
>> 8,7,6,6,1,1,1,9,5,9,0,9,2,1,6,4,2,0,1,9,8,9]
>
> Pardon me while I go UGH!... That must have been tedious to enter (and
> why double spaced). This may add a few milliseconds in processing (I'll
> explain later), but looks a lot cleaner:
>
> pi1000 = ("3.1415926535897932384626433832795028"
> "8419716939937510582097494459230781"
> <SNIP>
> "8766111959092164201989")
>
>
As for putting in the value for PI, it was actually rather easy. To get
the number itself, I just searched for and downloaded a file that had PI
to 1000 places and copied and pasted it into the editor. As for the
commas, at least to my current understanding of python, I thought those
had to between the elements of an array. As for putting in the commas,
I did that by using the "replace all" function in my IDE (or perhaps I
used gedit, a linux version of notepad) to replace all the "0" with
"0,", "1" with "1,", etc, so that was not very tedious and was actually
pretty fast. As for the double spacing, like I said it seems that
usenet (or perhaps my usenet viewer) seems to mess with spacing or
whatever, they do not exist on the actual program on my compputer.
> Python will concatenate adjacent strings, so that becomes just one long
> string internally -- if you were to "print pi1000" (Python 2.x syntax) it
> would display:
>
> 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420
> 1989
>
>
> Consider this; I spent way too much time generating the code when I
> should be out shopping for Christmas (watch out for line wrapping):
>
> -=-=-=-=-
> import math
>
> import matplotlib as mpl
> import matplotlib.pyplot as plt
>
> PI1000 = ("3.1415926535897932384626433832795028"
> "8419716939937510582097494459230781"
> "64062862089986280348253421170679821"
> "48086513282306647093844609550582231"
> "72535940812848111745028410270193852"
> "11055596446229489549303819644288109"
> "75665933446128475648233786783165271"
> "20190914564856692346034861045432664"
> "82133936072602491412737245870066063"
> "15588174881520920962829254091715364"
> "36789259036001133053054882046652138"
> "41469519415116094330572703657595919"
> "53092186117381932611793105118548074"
> "46237996274956735188575272489122793"
> "81830119491298336733624406566430860"
> "21394946395224737190702179860943702"
> "77053921717629317675238467481846766"
> "94051320005681271452635608277857713"
> "42757789609173637178721468440901224"
> "95343014654958537105079227968925892"
> "35420199561121290219608640344181598"
> "13629774771309960518707211349999998"
> "37297804995105973173281609631859502"
> "44594553469083026425223082533446850"
> "35261931188171010003137838752886587"
> "53320838142061717766914730359825349"
> "04287554687311595628638823537875937"
> "51957781857780532171226806613001927"
> "8766111959092164201989")
>
> def spiral_plot(digits):
> #create list of (x, y, color) tuples for the digits
> #(provided as a string); non-digits get the 11th color
> #X,Y are coordinates for an spiral
> x_coords = []
> y_coords = []
> xy_color = []
> mx = 0
> my = 0
> for p, d in enumerate(digits):
> #treating p as angle in degrees and as distance
> x = math.cos(math.radians(p)) * p
> y = math.sin(math.radians(p)) * p
> if d.isdigit():
> clr = int(d) #0..9 so
> else:
> clr = 10 #10 is the 11th color
> x_coords.append(x)
> y_coords.append(y)
> xy_color.append(clr)
>
> plt.scatter(x_coords, y_coords, c=xy_color, cmap=mpl.cm.Spectral,
> s=200)
> plt.show()
>
> if __name__ == "__main__":
> spiral_plot(PI1000)
>
> -=-=-=-
>
> NOTE: there are no doubt more efficient ways to work this -- for
> example, using NumPy arrays to generate the coordinates en-mass
>
>
Like I said, or at least think I implied, when I wrote the code I
posted, I did not even know that matplotlib or numpy even existed, just
the existence of the "graphics package" graphics.py. What I have
working, I do not need polar coordinates for, I need them for what I
have planned in my head for the indefinite future.
The code you posted appears to make professor Grimes "Roman bathhouse
tiling" representation of PI (I have not, as of when I typed this
message cut and pasted it into my IDE to see exactly what happens). I
think I will use it, or perhaps an adaptation of it for my "Roman
bathhouse tiling" representation of PI. Perhaps I will see if I can
adapt it to use NumPY, but I suspect that you can do that better than I.
--
My Yonkoma: https://www.flickr.com/photos/brian0908/albums/72157680223526176
The E-mail associated with the account is a "spamcatcher" account that I
got to every couple of months to empty out, and anything sent to it will
not be seen for probably several months, if it is seen at all.
Brian Christiansen
More information about the Python-list
mailing list