Re: [Edu-sig] Basic dictionary question
On 10/9/05, Kirby Urner <[EMAIL PROTECTED]> wrote: > I'll post again when I have more research behind me and either a solution or > concrete frustration in sight -- not before. I think you should just sort them by (x, y, z) and then comb through the list looking for near-adjacent matches. Basically you have to compare each point to all points following it in the list until the x coordinate is more than epsilon away. -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig
Re: [Edu-sig] Basic dictionary question
Kirby Urner wrote: > I'm translating a volume 3 cube around in a 3D checkerboard, trying to flag > all kitty-corner mid-edges (my bridge points), but not flagging border-line > edges where the connector tabs shouldn't appear -- some large borg-like > array of icosahedra connected by zig-zag tensed bands (Lanahan's patent > pending). > > See http://www.4dsolutions.net/satacad/pythonicmath/icosa_in_holder.jpg for > a picture of a unit cell (the array might contain thousands). > > So the XYZ tuples of interest are indeed highly distinct and in a regular > grid pattern. It's just that there're a whole lot of them, and if I could > find a hash key that'd keep only the unique ones unique and ignore floating > point fuzz, I'd be set. Any pairing/doubling would define a bridge point, > and therefore a green light to render a tab connector. > > I think the key is probably to transform the grid by scaling, such that my > mid-edge points of interest get expressed using all integer coordinates. > Even though my actual map is floating point, the isomorphism will work for > pruning, and the tuples'll be easy to manage (so maybe scratch the decimal > type idea for now). > > I'll post again when I have more research behind me and either a solution or > concrete frustration in sight -- not before. > > Kirby Does something like this work? The idea is two exact matches on the discretization and one off-by-one on the third discretization merits a check. discrete(point) gives the "integer-ized" coordinates. There is some fancy dancing to avoid the distance check (done as the square just to avoid a few square roots) unless possibly helpful. It only tries to solve "near-misses" (skips exact matches) on the theory you can already get the exact matches from a dictionary. def clustered(source_of_points, threshold2) xy = {} xz = {} yz = {} for point in source_of_points: ix, iy, iz = discrete(point) xy.setdefault([]).append((iz, point)) xz.setdefault([]).append((iy, point)) yz.setdefault([]).append((ix, point)) for collection in (xy, xz, yz): for parts in collection.itervalues(): if len(parts) > 1: parts.sort() for (da, a), (db, b) in zip(parts, parts[1:]): if 0 <= db - da <= 1: if 0 < dist2(a, b) < threshold2: yield a, b -- -- Scott David Daniels [EMAIL PROTECTED] ___ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig
Re: [Edu-sig] Basic dictionary question
> I'll post again when I have more research behind me and either a solution > or concrete frustration in sight -- not before. > > Kirby OK, I've got a solution working. Here's an interim result: http://www.4dsolutions.net/satacad/pythonicmath/connectorstudy2.jpg Notice how the zigzag metal bands connect jade icosahedra and don't clutter the unit cell otherwise, i.e. no extra tabs that don't go through bridge points. I ended up using a feature specific to my vector class: the bridge points all had 4-tuple signatures with floats = multiples of 1/2. So I used a little round and chop function that appears to have worked: @staticmethod def _mktuple(qray): thecoords = qray.coords thelist = [] for c in thecoords: t = float(str(round(c,5))[:4]) thelist.append(t) return tuple(thelist) The 4-tuples are all positive, even in xyz octants w/ negatives, thanks to quadray vector algebra. I stuffed 'em into a dict like this: def add2pairs(adict, thekeys): for newkey in thekeys: adict[newkey] = adict.get(newkey,0) + 1 return addict ...then permitted only those with value = 2 to render. Special thanks to Guido and Scott for helping me grabble with this issue. Kirby Note: Here's the stuff photographed in time/size (vs. rendered): http://www.4dsolutions.net/satacad/pythonicmath/lanahan_artifact.jpg (photo by Dave Ulmer @ Linus Pauling House, wwwanderers.org) ___ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig
Re: [Edu-sig] Basic dictionary question
Kirby, Do you have a left and right stereo pair on that rendering? I just can't make heads or tails of it w/o true 3D :-) --John Kirby Urner wrote: >>I'll post again when I have more research behind me and either a solution >>or concrete frustration in sight -- not before. >> >>Kirby > > > OK, I've got a solution working. Here's an interim result: > http://www.4dsolutions.net/satacad/pythonicmath/connectorstudy2.jpg > > Notice how the zigzag metal bands connect jade icosahedra and don't clutter > the unit cell otherwise, i.e. no extra tabs that don't go through bridge > points. > > I ended up using a feature specific to my vector class: the bridge points > all had 4-tuple signatures with floats = multiples of 1/2. So I used a > little round and chop function that appears to have worked: > > @staticmethod > def _mktuple(qray): > thecoords = qray.coords > thelist = [] > for c in thecoords: > t = float(str(round(c,5))[:4]) > thelist.append(t) > return tuple(thelist) > > The 4-tuples are all positive, even in xyz octants w/ negatives, thanks to > quadray vector algebra. I stuffed 'em into a dict like this: > > def add2pairs(adict, thekeys): > for newkey in thekeys: > adict[newkey] = adict.get(newkey,0) + 1 > return addict > > ...then permitted only those with value = 2 to render. > > Special thanks to Guido and Scott for helping me grabble with this issue. > > Kirby > > Note: > > Here's the stuff photographed in time/size (vs. rendered): > http://www.4dsolutions.net/satacad/pythonicmath/lanahan_artifact.jpg > (photo by Dave Ulmer @ Linus Pauling House, wwwanderers.org) > > > ___ > Edu-sig mailing list > Edu-sig@python.org > http://mail.python.org/mailman/listinfo/edu-sig > > -- John M. Zelle, Ph.D. Wartburg College Professor of Computer ScienceWaverly, IA [EMAIL PROTECTED] (319) 352-8360 ___ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig