Message from guest speaker Neil Sloane.

One of the students in the class asked me what algorithm Scott Shannon used to choose the colors. Here is his reply:

It would depend on how the student's program is constructing the drawing:… if its just simply working out the points around a circle and then drawing the lines…. it's very difficult to do nice coloring as it knowns nothing about the polygons the lines are making. My program tracks the new inner polygons created with every cutting line across the inside of the original polygon, so at the end I know all the info about all the polygons i.e. the number of sides and the coordinates of all their points. I then just have a simple function in each polygon object to average the distance all off its points from the coordinate origin. So each polygon ends up with one average distance number. I then look at the maximum distance found across all polygons, and then divide that distance into 1000 little distance buckets, and assign each polygon into one of those buckets based on its own distance. So this means all the polygons are distributed in an array of length 1000, the index of which corresponds to a distance from the origin. To make it interesting I then randomize that array, and then spread the 1000 indexes across the 7 colors of the rainbow that I have defined as the basic color palette. I can play with that palette as required, if I want more colors like real stained glass windows I can say give 4 reds, 4 blues, 1 yellow and 1 green, so red and blue will dominate but there will be a few yellows and greens and the colors between those. If one does not randomize the array then one just gets a perfect color change across the rainbow from red to violet starting from the middle of the polygon and moving outward… not very interesting! But the randomizing of the indexes makes all the interesting pictures you see.

That's doing the random coloring, when I do the edge-count coloring then its same same but I don't randomize and instead of using the distance value I use the edge count value into the index of the array, obviously the array in this case will on have 2,3,4,5 ... entries depending on how many different n-gons are found.

The above is a fairly complicated algorithm due to various issues about how you work out where the polygon is cut and how you correctly distribute the points it has into two new polygons. There are 3 cases that have to be considered point to point, point to line, and line to line. The point-to-point intersections are the most troublesome as they can also detect the edge they are on also being cut, so one has to then do some intelligent guesswork about the "real" intersection. I have mentioned this in the past about how one decides if the line is going through a point or just very very close to it. In the limit of millions of points my program will eventually break as it will not be able to tell within its tolerance value (that I arbitrarily set to something like 10-100 , but who knows what it should be?!) when a line cuts at a point or just very very close to it. Having said that when I was talking to my son the other day he mentioned something that lead us to think of a possible way around that (which I probably wont implement myself but someone could in the future if mentioned in the paper). Each point (and/or line) carries around with it the equation in pure form of the 2 lines that formed it by intersection. i.e. don't "solve" these line equations, keep them in their true form. Then if one finds a line and edge intersection that is very very close to a point, one could solve the equations to a much much higher precision, down to millions of decimal points if required as arbitrary precision maths packages will allow that. Do that recursively if required with ever increasing precision until once can definitely split the point intersection from the edge intersection, and this will allow for a near perfect determination of all intersections.

Having said all that, this does not help your student if they have just drawn the polygons by drawing lines across the outer circle etc. in that case there isn't much I can suggest as one really needs to know the info of all the little polygons formed in the cutting that's the hard part, and why I guess nobody had bothered with it. Well until now ha!. But once you have that then just following what I outlined above is fairly easy.