Friday, August 13, 2021

I zonked out and didn’t get my drabble done last night 8-(

I did squeak by on posting some code. I was supposed to work on random marching triangles but ended up writing a triangle fan blob inside of an ellipse representing my old python obsession with a pointy, or ‘pointed’ as docs insists, oval world map.

What I can do is use a circle or an ellipse and start with a north polar triangle fan polygon. We can further subdivide the world south of these triangles and vertices into a strip of quads which are subdivided into triangle pairs between the implied south polar triangle fan polygon. The strip of quads is already a set of polygon quads, but we can group quads and triangles into polygons which lie between the two polar polygons. This is a rather clunky way of making a spherical polyhedron!

I can do a version of an oval world map subdivided with my broken egg-shell model. I draw an oval-shaped polygon with vertices and edges approximating an oval, then use those points to subdivide the oval-shaped polygon by picking two points on the border of the polygon to connect and subdivide that polygon into two daughter polygons. To do this I will need to make that parent oval polygon by going around the circumference in order and in the same direction, clockwise for preference, down the right side and up the left side back to the starting point. I build a list of array of points in two parts-

  1. Starting at height 0 at the top of the oval, which in this case is more actually a circle with a unit radius of one half, if becomes an oval or ellipse in CSS or the polygon by being twice as wide a tall, the coordinates are 0 to 100%, 0 to 100%, we randomly move down the box from top to bottom. I have a y minus radius and add a little bit to it, then find an x, converting that to a polygon x and polygon y by adding radius. We add another little bit to y and find a second x, doing this again and again until we get a y greater than positive radius. Then we stop, discarding the last point which doesn’t make sense for my circle or oval anyway. This is all saved to a list of x,y, of course.

  2. Then we go through this list in reverse, adding -x,y points, mirroring the first side ro get the other side of the circle or ellipse.

  3. Finally we go through the list again, adding a radius of one half to get positive x,y coordinates to feed to CSS and make polygons!

Whew! We now have a 2D oval corresponding to the longitude and latitude of a 3D world. We can run a line or a dog-leg preferably from one latitude point across the oval to the same latitude point to subdivide the world into a pair of polar polygons. We can connect any two points on the oval with a loop to make a smaller daughter polygon and the rest of the world is it’s sibling, greater polygon. Any three points on a curve, or even the approximation of a curve, make a triangle and therefore the simplest polygon. So each pair of points must be separated by at least one point and we make some sort of loop inside the world polygon, finding at least one point between the two random endpoints so that the daughter polygon is a quad/triangle pair; triangle meshes are important for calculating the area of these polygons.

  1. To subdivide, we pick a point at random, then pick another point at random, figure out if they are more than one point apart and order them lowest to highest to get a clockwise stretch.

  2. The two endpoints need to be connected by another stretch of clockwise points, this time from the highest point to the lowest point. We fractalize the line by randomly picking a midpoint and displacing the point a bit to the right or left of the line, doing this several times until we get ‘close enough’ to the end point.

  3. We keep track of the initial stretch of points and the new stretch of points and make a new clockwise daughter polygon.

  4. It’s sibling is the rest of the parent polygon, clockwise, then splice the new stretch of points in reverse. This gives us two clockwise daughter polygons from the parent polygon plus some new points.

  5. Finally, we can recursively subdivide daughter polygons until we can’t.

I will need to implement this to actually show what I’m talking about, but I think I have a workable roadmap now.


No comments:

Post a Comment