Saturday, February 2, 2013

Geologeez Nutz

Not done anything lately on tectonics simulations, but I realized that there was a bunch of crap I'd done last fall that I had never posted about, so thought I'd describe it, to remind myself where I left everything if for no other reason.

The main change was making tiles have layers of rock instead of just single elevation values, and different rock types for each layer.

The first continent is a hunk of igneous extrusive rock of varying composition, and the planet begins with no atmosphere or life:

Initial supercontinent with no life

When the atmosphere kicks in then you get erosion, which varies based on climate and grinds layers from the top down to create sedimentary rock of progressively smaller grain sizes.

When life shows up there is an additional organic component to sediments, which makes limestone and chalk in the right environment that can in turn make marble, though probably too rarely. Life marks tiles as having peat bogs where it makes sense as well, so there's the potential to figure out where fossil fuels end up.

Crustal thickness leads to regional metamorphism, and subduction causes igneous intrusions with associated contact metamorphism. Erosion affects rocks based on how tough they are, so fresh mountains should grind down to craggy hornfels and granite shields should eventually emerge.

The merging of tiles due to the constraints of math on a sphere tries to preserve uniqueness, so peak elevations and metamorphic layers don't get averaged away. Not scientifically justifiable, really.

I added the ability to click on a tile (in the Mercator and Sinusoidal projections) and see the layers of that tile, with a tooltip showing the full composition of a given layer. I also added the crappy "color" display mode that mostly just suddenly turns green when life shows up and then shows you where mountains are:

Layer information with composition tooltip

I also did some profiling that led to some optimizations, mainly around the bogus climate model but also caching various calculations that were repeated all over the place. This got things moving quick enough that I could start thinking about supercontinent cycles again, but none of the various forays I made into getting any of that to work out nicely panned out.

Planet with a couple continents showing different climates

The other improvement in the offing is figuring out metals, basically banded iron formations and the veins of stuff that go along with igneous intrusions and create placer deposits when they erode.

Also found a dude on Reddit who has a similarly-conceived project, pyTectonics. He's taken a more scientifically rigorous approach and does things on a Fibonacci grid, which looks pretty awesome. I'm not exactly sure, but it also sounds like he creates and destroys new grid points as needed, which is a cool idea.

Edit: Forgot to link to the source.

Thursday, December 27, 2012

Monday, August 20, 2012

Mountain? Climate!

I had put together a crappy climate model before I had really read anything about meteorology: basically, vary insolation based on season, have prevailing winds pick up moisture from the sea and rain it down according to elevation, and then use the results to classify the climate.

So no meandering jet streams or mid-latitude cyclones or anything, but I've had enough trouble even figuring out where to start on a more legitimate climate and weather simulation that I decided to just bring the old broken one into the tectonics simulation as a placeholder.

Here's my fake climate simulation at work:
World map with Koeppen categorizations that are all wrong.
Note the great Saudi Arabian jungle, the desert in the Southeast US (but not the Southwest), the frozen British Isles, &c.

So despite the brokenness, I wanted to get some sort of climate system in so it could contribute to the erosion algorithm, modulating the erosion amount from each tile by its annual precipitation and "polar" status (on the theory that glaciers cause a lot of erosion regardless of precipitation).

Compare erosion under the old algorithm (reddishness represents height lost to erosion, greenishness height gained by deposited eroded sediment):
World map showing erosion rates based solely on relative elevation;
versus the new erosion modulated by precipitation:
World map showing erosion rates based on relative elevation and climate.

I had to tweak a magic number that had been picked to keep mountain building and erosion somewhat in balance. But after that, a newly created world came out looking pretty good:
A generated world map;
and its "climate":
Crappy climate map of the previous generated world.

In any case, it doesn't really change the current simulation very much, but it does lay the groundwork for some more interesting recording of geological history. Source.

Friday, August 3, 2012

Fixing a Hole

My previous "plates on a sphere" simulation tended make continents that were too round. This was because of how I tried to resolve an issue stemming from my whole approach to the spherical geometry.

The sphere is divided into "tiles" of approximately equal size, each with a fixed location (a vector on the unit sphere). So at any point in time, a continent is defined as a set of those tiles.

When a continent moves, the vectors of all of its tiles are moved (that is, rotated around an axis) by a given amount; then the closest tile to each of those resulting vectors gets the value of its source tile.

Because of how the tiles are distributed (near the equator, almost a grid; at the poles, not anything like a grid), there is never a neat 1-to-1 mapping of source to destination tiles (unless the continent is centered on the equator, moving due West or East).

Which means there are lots of instances of more than one source tile mapping to the same destination tile, and tiles that are visibly part of the continent in its final position but that weren't mapped to by any source tile, and thus appear as holes.

My previous solution to this problem had been, at each step, to map each source tile to the nearest two destination tiles; to prevent the continent from growing out of control, I then trimmed off a bunch of tiles, starting with those most distant from the middle of the continent. This caused the progressive roundening, which sort of makes intuitive sense (sharp edges ground down over time) but doesn't look very realistic (Earth has lots of pointy continents).

My new strategy is to identify potential holes (tiles adjacent to those identified as belonging to the continent in its new position but that aren't themselves part of the continent's set of tiles), and rotate their positions backwards to see if the nearest tile to that location was part of the old set. If so, then add it to the new set, then check the tiles adjacent to that one, and so forth.

The resulting continents are much more satisfyingly pointy:


Tuesday, June 19, 2012

Thursday, May 24, 2012

Tectonic Youth

I've been working on a somewhat reasonable-looking plate tectonics simulation.

Looking for something along these lines, I had found an open-sourced VB app called World Builder, which uses David Allen's cdrift (around halfway down) algorithms for simulating something like continental drift on a toroidal topology; I believe that was influenced by Mark Isaak's plates.c (same as last link) program.

From my very rudimentary understanding of geology, it seems like the major disparity between how these simulations played out and what an Earthlike planet should look is purely geometrical: continents that split up and move around a torus are going to run into each other in different ways than on a sphere, and continents tend to break up along 120-degree angles.

So I basically implemented cdrift's general approach (build up continents' leading edges, erode to neighboring tiles, and split and merge plates at random), but on a sphere broken up into approximately evenly-sized tiles (latitudes spaced evenly, and as many squarish tiles as fit in each latitude). The results aren't terrible (same simulation state in three different projections):

 

It's slow as hell (maybe ~2s a step on my computer), because math is hard, though there are surely opportunities for optimization.

Friday, December 9, 2011

Goldistocks

In re this post, there actually is a simple way to bet against gold, which is by buying a gold short fund like DGZ. Which if I had done it in May of last year, I'd be down to like 55% of my investment. But that means it's a perfect time to buy, right?

Wednesday, May 4, 2011

Good enough or worse than not at all

I was reminded recently of an idea mentioned in an xkcd mouseover text: to keep yourself from being distracted by crap on the internet, put a 30-second delay before opening up a new webpage. I searched and someone had wroten a little script to do that.

I don't know if I screwed something up installing it or whatever, but the script appears to work erratically: sometimes correctly, sometimes showing a countdown on its icon but not obscuring the page, and sometimes having no effect at all.

The upshot being, the anti-distraction mechanism itself ends up replicating the "slot machine" sort of dynamic that makes things like web forums, Twitter feeds, and news sites so distracting in the first place. Being able to instantly check Reddit for new stories whenever you want is habit-forming, but only being able to do so 10% of the time is even worse!

Anyway, just found that amusing or whatever.

Wednesday, April 27, 2011

Celestiality

I wanted to be able to generate random but plausible celestial spheres of stars visible to the naked eye from the vantage point of a solar system like ours, situated in an arm of a spiral galaxy.

I grabbed all the stars in ESA's Hipparcos catalogue with apparent magnitudes below 6, which comes to a little over 5000 stars. Mapped out on a sphere according to apparent magnitude and color they look like:

Stars visible by naked eye from Earth

That's a sinusoidal projection of the whole sphere, as would be seen from inside of it (on the Earth, for example). I sanity-checked it by filtering out all but the stars of the Big Dipper and made sure it dipped in the right orientation and hemisphere.

Plotting their absolute magnitudes versus their color index looks like this:

Plot of each visible star's absolute magnitude versus color index

The hunk on the left is made of stars on the main sequence, and the other splotch of giants, with a spattering of others. Most of the stars around us are red dwarrows, but since they're too small and dim to see with the naked eye, I don't even care about those.

A histogram (excuse the rotation and scaled-up x-axis) looks like:

Histogram of visible stars' magnitudes and colors

I smoothened that out to make a probability distribution (scaled up, and apologies for yet another axis rotation):

Distribution for randomly generating stars of different magnitudes and colors

You can't see it, but outside the main globs there are big regions of "off-white" (grays 253 and 254) where there are small but nonzero probabilities of finding stars.

One thing I had not expected was that even without rendering a "milky way," the visible stars are noticeably more prevalent closer to the galactic disk. So I also found a best fit great circle and recorded each star's angular distance from that. Plotting those on the z-axis gives:

Distance of stars from galactic disk versus magnitude and color index

You sort of need to move it around to tell what's going on, but basically stars are more likely to be near the disk, and more so if they're brighter and whiter. I didn't even try to quantify this any better, just fudged it.

So I generate 6000 (or however many) stars with color and magnitude selected according to my smoothified histogram. Each star gets a random distance within visibility range (because my initial sample only included stars of a given color close enough to be visible to the naked eye, I can't create any too far away to see without throwing off the distribution) and is either randomly rotated away from the galactic plane or rotated according to a normal distribution, more likely the latter the brighter and whiter it is.

Results shown on the right, alongside plots of the Hipparcos data set on the left (and as shown above).

Plots of empirical and randomly generated star distributions

The results aren't too bad, though that lowest-probability shade in my smootherized histogram is too dark: it should probably be like gray 254.9 or something.

Finally the whole thing gets a random rotation from the galactic plane, and the results might look something like this:

Random starscape

So pretty good! Next step (after tweaking the distance-from-galactic-plane function) would be generating some realistic views from a planet according to axial tilt and times of day and season. And then inventing constellations?

Also maybe the possibility of a perspective from outside a galactic arm? Though how likely is that, if you're looking from a class G or K main sequence star?

I don't know. I think it's cool though.

Source here, requires pygame, numpy, and matplotlib.

Saturday, April 23, 2011

Sight Gag

Had this idea the other day, not sure if it's been done.

Car air freshener hanging from a helmet-mounted bike mirror

Thursday, April 7, 2011

Software Idea

You enter the ingredients list and nutritional information of a food product, like what's printed on the package. The system looks up the nutritional data for each individual ingredient. That information, plus the inequalities implied by the order of the ingredients list, allows it to solve for the relative quantities of each ingredient (giving ranges where an exact amount can't be determined, such as for ingredients with no measured nutritional value).

Basically I want to reverse engineer this here granola.

Sunday, February 13, 2011

31337 is Prime

Did not know that.

Tuesday, January 11, 2011

Unicode Joke?

Am I crazy or does Unicode character 221B look like a Sherlock Holmes pipe?

Thursday, November 11, 2010

Obama the Leftist

Righteous rant from Kevin Carson:
Obama lied when he said, "There is not a rich America, and a poor America….  We are one nation, one people."

...

The Iraqi worker is my fellow countryman.  The American plutocrat is my enemy.

Wednesday, November 3, 2010

Hate This

I love bike lanes, but this shrill denunciation of people parking in bike lanes during church is ridiculous: it's Sunday morning; you're not commuting; and church aside traffic is generally light. So just grow a pair and take the damn lane.

In addition, cycling advocates are done no favors by spandexed hobbyists exhorting cops to write parking tickets to old ladies in church hats. Bike lanes should be about safe transportation infrastructure, not staking out territory for yuppies.

Saturday, October 30, 2010

Polygons on a Sphere

It's this shape:
Convex polygon with no holes.

And a couple of instances of them go around a sphere in different directions (the blue dot shows the orientation, which is different from the direction of travel, and the red dot is the centroid):

Far from the center of the projection, they get distorted:
Polygons distorted near the edge of the projection.

When one wraps around to the other side of the projection it gets all screwy, but I couldn't get a screen cap.

Same repository as last time, now additionally depends on Shapely.

Wednesday, October 20, 2010

Weak

Contra xkcd, I'm sure thousands of corporations are helmed by people who seek guidance in prayer, horoscopes, tarot, &c. and doing just fine.

Most of these ideas don't even theoretically make sense ("health care cost reduction" isn't a market anyone can "make a killing in," which is why governments have to step in; I believe remote viewing is supposed to require people at the remote location; if the military were using hexes then they would probably keep quiet about it, and they have certainly at least tried it; and I don't think anybody would expect "crystal energy" to be energy in the sense of the physics term "energy").

And in any case, just because "capitalism" is "profit-focused" doesn't mean that individual firms succeed in discovering every possible path towards maximizing profits. Ruthlessness doesn't imply omniscience.

Tuesday, October 19, 2010

Dollar? I never even &c.

Via Atrios, I knew that it was widely believed that the US would not act to devalue the dollar, but I was also under the impression that the context of that position was that, while a falling dollar would be (potentially) beneficial to our economy, there are some number of reasons against trying to pursue those ends. I didn't realize Geithner's position was actually in the opposite direction, that we need to do all we can to strengthen the dollar.

I mean fair enough, some people are in the "let's try anything" camp while others are more towards the "let's not mess with anything and see how it shakes out" side of things. "Let's take whatever people in the 'try anything' camp suggest and run in the opposite direction" seems so pointlessly sadistic as to be off the reservation entirely.

You camp on a reservation right.

Sunday, October 10, 2010

Livin' on a Sphere

I've been mucking about trying to get something that looks something like what's described here, but on the surface of a sphere (not about to try modeling any kind of actual fluid dynamics, just trying to mimic the behavior).

I used a sinusoidal projection so each screen pixel represents about the same area of the sphere. It took me way too long to figure out I should be using regular old vectors in R3 instead of muddling through with latitudes and longitudes.

Brighter green points are heavier, and the blue point is their weighted average. The red point repels the green points and moves to the blue point whenever the green ones slow down sufficiently.

So this is early in a cycle, when the red point has recently moved to the weighted average location:

Early in cycle, origin of impulse close to center of points.

And this is later on in a (later) cycle, as the repelled points are converging towards the antipode:

Later in the cycle, new center far from origin of impulse.

Source here ("Heat2.py" is shown, but there's other related crap in there), requires Numpy and pygame.