recent wheel spinning... (spatial geom)
Apologies in advance for my ramblings. Something here might be of interest to anonymous readers... Last night and today were all about dusting off old skills and using Python in a Jupyter Notebook to showcase renderings by the free raytracer POV-Ray ( povray.org). The topic is pure geometry, no fancy textures required. In the meantime I'm looking at both Rhino (proprietary) and Blender (open source), partly because C6XTY / Flextegrity wants to get itself into the hands of more software engineers and partly because Coding with Kids is looking at teaching more 2D / 3D graphics (partially covered in the current suite of tools, but room for growth). These are both CAD programs for doing 3D animations and renderings, both with Python APIs. I learned from my teaching job with kids that even Chromebooks have access to some kind of Blender in the cloud. Didn't know that until last week. This kid sounds like one of our students: https://youtu.be/JlydssSG5Iw Here's the Jupyter Notebook in question. The only dependency is qrays.py in the same Github repo [and of course povray if the goal is to do renderings]. https://github.com/4dsolutions/Python5/blob/master/Generating%20the%20FCC.ip... Zooming out: what I think might interest high schoolers, just learning about XYZ, spherical coordinates and so on, is some exposure to these arcane alien esoteric "quadray coordinates" that use 4-tuples instead of 3-tuples to map points in space (no negative numbers required). I've got lots of material on 'em but don't claim credit for inventing them (more a popularizer, implemented 'em in Python and Clojure, Tom Ace in C++). http://mathforum.org/library/view/6236.html What's appealing is they're conceptually accessible, not hard to grok, yet there's so much room for original research. Clearly four spokes divide space into four quadrants and any point is reachable by adding up to three (stretched or shrunk -- but not reversed) per the usual vector scaling and addition operations. The centers of all balls in what we call the FCC or CCP packing (core in crystallography), starting with a nuclear sphere then 1, 12, 42, 92... balls packing outward in shells (see OEIS [1]) may be given all-integer 4-tuple coordinates using qrays. Example (these are the 12 ball centers around a nuclear center, at the corners of a cuboctahedron with origin at (0,0,0,0) (note: ivm_vector is same thing as qray, of namedtuple type in collections library). {ivm_vector(a=0, b=1, c=1, d=2), ivm_vector(a=1, b=2, c=0, d=1), ivm_vector(a=0, b=1, c=2, d=1), ivm_vector(a=0, b=2, c=1, d=1), ivm_vector(a=2, b=1, c=0, d=1), ivm_vector(a=1, b=2, c=1, d=0), ivm_vector(a=1, b=1, c=2, d=0), ivm_vector(a=2, b=1, c=1, d=0), ivm_vector(a=1, b=0, c=2, d=1), ivm_vector(a=2, b=0, c=1, d=1), ivm_vector(a=1, b=0, c=1, d=2), ivm_vector(a=1, b=1, c=0, d=2)} Today I realized that to add Qrays to a set, they'd need to be (a) hashable and (b) usable with == i.e. __eq__ would need to have meaning. Without __eq__, every instance was being seen as unique. That add to the set OK, but dupes were not thrown out. They'd hash, but not on the 4-tuple content, what __eq__ now provides. Here's that code fragment: def __eq__(self, other): return self.coords == other.coords def __hash__(self): return hash(self.coords) Most recent qrays (there's an ordinary XYZ vector type too -- and the means to go back and forth): https://github.com/4dsolutions/Python5/blob/master/qrays.py (I keep updating this, like I notice I need to update the comments to say I updated the file just today) The algorithm for getting successive layers of balls (1, 12, 42, 92...) is to add all 12 balls around every ball in shell N, but then discard (simply by using the set object for storage) all those balls already in shell N or shell N-1, generating only balls in shell N+1. nucleus = {qrays.Qvector((0,0,0,0))} layer1 = tuple(map(qrays.Qvector, ((0, 1, 1, 2), (1, 0, 1, 2), (2, 0, 1, 1), (0, 2, 1, 1), (0, 1, 2, 1), (1, 2, 1, 0), (1, 1, 2, 0), (2, 1, 1, 0), (1, 0, 2, 1), (1, 2, 0, 1), (2, 1, 0, 1), (1, 1, 0, 2)))) def next_layer(curr_layer, prev_layer): next_layer = set() for qv in curr_layer: for bv in layer1: v_sum = qv + bv if (not v_sum in curr_layer and not v_sum in prev_layer): next_layer.add(v_sum) return next_layer nl = next_layer(nucleus, nucleus) # 1-freq nnl = next_layer(nl, nucleus) # 2-freq nnnl = next_layer(nnl, nl) # 3-freq print("Number of balls in successive layers:") print(len(nl)) print(len(nnl)) print(len(nnnl)) If you click on the Notebook you'll see what I mean by "shells". More here: https://github.com/4dsolutions/Python5/blob/master/STEM%20Mathematics.ipynb Anyway, quadrays or "caltrop coordinates" are pretty freaky and I think help XYZers better appreciate what the orthodoxy is. When you've seen something alien, you better appreciate the status quo. I took C6XTY out to Saturday Academy on the campus of University of Portland [2], to see Rhino and Jupyter Notebooks running on Windows7. Jupyter Notebooks at least is something to have on your resume if thinking about college. It's about working with way more than just Python. I think I posted those recent articles already. Kirby [1] http://oeis.org/A005901 (my name under links, still trying to make it viral) [2] C6XTY @ sa: this Thursday: https://flic.kr/p/HnGeut (sa: is where I've taught Martian Math before) http://www.4dsolutions.net/satacad/martianmath/toc.html http://wikieducator.org/Martian_Math
[2] C6XTY @ sa: this Thursday: https://flic.kr/p/HnGeut
(sa: is where I've taught Martian Math before) http://www.4dsolutions.net/satacad/martianmath/toc.html http://wikieducator.org/Martian_Math
In this post I'm merging two threads: (i) introduce some of the high end 3rd party stuff early e.g. science stack numpy and pandas (ii) segue a geometry that requires some rethinking of familiar orthodoxies. Example: pd.options.display.float_format = '{:,.3f}'.format data = pd.DataFrame(vectors, columns = index) print(data) Vtype ivm xyz Coords a b c d x y z 0 0.000 1.000 1.000 2.000 0.000 -0.707 -0.707 1 1.000 0.000 1.000 2.000 0.707 0.000 -0.707 2 2.000 0.000 1.000 1.000 0.707 0.707 0.000 3 0.000 2.000 1.000 1.000 -0.707 -0.707 0.000 4 0.000 1.000 2.000 1.000 -0.707 0.000 -0.707 5 1.000 2.000 1.000 0.000 -0.707 0.000 0.707 6 1.000 1.000 2.000 0.000 -0.707 0.707 0.000 7 2.000 1.000 1.000 0.000 0.000 0.707 0.707 8 1.000 0.000 2.000 1.000 0.000 0.707 -0.707 9 1.000 2.000 0.000 1.000 0.000 -0.707 0.707 10 2.000 1.000 0.000 1.000 0.707 0.000 0.707 11 1.000 1.000 0.000 2.000 0.707 -0.707 0.000 Getting such multi-indexing requires such as: arrays = [['ivm', 'ivm', 'ivm', 'ivm', 'xyz', 'xyz', 'xyz'], ['a', 'b', 'c', 'd', 'x', 'y', 'z',]] tuples = list(zip(*arrays)) index = pd.MultiIndex.from_tuples(tuples, names=['Vtype', 'Coords']) Call it business math if you like, micro-management of data tables via some command line interface. https://en.wikipedia.org/wiki/In_the_Beginning..._Was_the_Command_Line That's using the multi-indexing phenomenon (object) the pandas dataframes provide. Above, I'm showing vectors in two notations, side by side, with a link to their colorful depictions, in terms of ball packings, at this still improving Jupyter Notebook: https://github.com/4dsolutions/Python5/blob/master/Generating%20the%20FCC.ip... Next challenge is to segment the dataframe vertically, into nucleus (1) plus successive layers (12, 42, 92...). Kirby
On Sat, May 12, 2018 at 2:25 PM, kirby urner <kirby.urner@gmail.com> wrote:
https://github.com/4dsolutions/Python5/blob/master/Generating%20the%20FCC. ipynb
Next challenge is to segment the dataframe vertically, into nucleus (1) plus successive layers (12, 42, 92...).
Kirby
Done! #%% # hierarchical row levels arrays = [['layer0'] + ['layer1'] * 12 + ['layer2'] * 42, range(1 + 12 + 42)] tuples = list(zip(*arrays)) rowindex = pd.MultiIndex.from_tuples(tuples, names=['Shell', 'Ball']) #%% Those weird %% thingys are I-Python / Spyder's way of letting run down a script in discrete chunks. To give a sense of the data: Vtype ivm xyz Coords a b c d x y z Shell Ball layer0 0 0 0 0 0 0.000 0.000 0.000 layer1 1 0 1 1 2 0.000 -0.707 -0.707 2 0 1 2 1 -0.707 0.000 -0.707 3 0 2 1 1 -0.707 -0.707 0.000 4 1 0 1 2 0.707 0.000 -0.707 Sharing this JN out to Facebook on math teacher group: https://www.facebook.com/groups/147158235484661/ Great for anyone into linear algebra at all. Kirby
participants (1)
-
kirby urner