Live data from Hacker News

Island Generator

exupero.org

21–30 of 33 posts

Re: Island Generator

#21
post #12

Great writeup! Notice that range stops just shy of 2π. Floating point math sometimes produces a final angle indistinguishably close to 2π, adding one extra vertex to our n-gon. To see for yourself, change (- tau 0.000001) to tau and set the number of sides to 6. You’ll see an extra point in the output very close to the starting point. This is a "trick" that you find everywhere in graphics programming, and I can't bel…

It wouldn't have been a problem if it instead used an index variable i ranging from 0 to the number of sides, computing 2pii/sides along the way.

If you're going to rely on repeated addition of irrational numbers to come out to some exact value, then you've misunderstood the abilities of finite decimal representations. It is something easy to overlook, but shouldn't be too surprising to someone who has computed anything by hand (for instance, try long dividing 1/7 out to some number of decimal places, and then adding the result to itself seven times --- if it's a problem there it's not simply a tooling issue, assuming of course the problem isn't with decimals!).

Though, if we want to fix our tools, perhaps instead of the promise of a "cos" or "sin" functions, we could have (ngon-point i n) which returns [(cos (/ i n)) (sin (/ i n))]. Then you wouldn't be tempted to use floating-point numbers to represent the index of a polygon vertex.

Re: Island Generator

#24
post #21
post #12

Great writeup! Notice that range stops just shy of 2π. Floating point math sometimes produces a final angle indistinguishably close to 2π, adding one extra vertex to our n-gon. To see for yourself, change (- tau 0.000001) to tau and set the number of sides to 6. You’ll see an extra point in the output very close to the starting point. This is a "trick" that you find everywhere in graphics programming, and I can't bel…

It wouldn't have been a problem if it instead used an index variable i ranging from 0 to the number of sides, computing 2 pi i/sides along the way. If you're going to rely on repeated addition of irrational numbers to come out to some exact value, then you've misunderstood the abilities of finite decimal representations. It is something easy to overlook, but shouldn't be too surprising to someone who has computed any…

I fully agree.

As a more general strategy, just use integers (preferably unsigned integers) for all critical stuff such as state handling and looping over. Then, perform floating point operations only on top of that, as a last step. Sometime you don't even need that and use fixed point arithmetics instead (i.e. change your unit to some fixed fraction, e.g. in accounting calculate with integer cents instead of floating point euros/dollars).

Re: Island Generator

#25

Earlier quoted context omitted.

Yes, this is one of the main approaches when I was looking at this. Sorry, don't have references at hand, but recall comng across a few when searching for "hydraulic" erosion and river formation. IIRC, it took a little while to find the favoured search terms. I was using http://citeseerx.ist.psu.edu/ and http://scholar.google.com.au/ There's an interesting review paper by Musgrave (decades after he was lead author on…

Thanks for the Musgrave reference, I'll check it out. As far as your geological questions: 1) Silted up seas and canyon-filled mountains aren't actually that inaccurate. Mountains as we think of them are highly eroded, basically just the remnants of much larger volumes of rock that were uplifted. I'd ballpark a 'typical' mountain range (Rocky Mountain front range, Appalachians, Alps, NZ Southern Alps) at having 10-20…

Thanks for taking the time to explain some geology/plate tectonics in an accessible way. HN is great for the random educational diversions away from plain old tech.

Re: Island Generator

#26
See also the venerable xmountains (possibly already installed on your workstation).

Screenshot: https://osde8info.files.wordpress.com/2007/02/6a00d4141b9517...

There's a writeup on how it works:

http://www2.epcc.ed.ac.uk/~spb/xmountains/about_xmountains.h...

I don't know how old it is, but the timestamp at the bottom of the HTML file above is 1997.

Re: Island Generator

#27
post #21
post #12

Great writeup! Notice that range stops just shy of 2π. Floating point math sometimes produces a final angle indistinguishably close to 2π, adding one extra vertex to our n-gon. To see for yourself, change (- tau 0.000001) to tau and set the number of sides to 6. You’ll see an extra point in the output very close to the starting point. This is a "trick" that you find everywhere in graphics programming, and I can't bel…

It wouldn't have been a problem if it instead used an index variable i ranging from 0 to the number of sides, computing 2 pi i/sides along the way. If you're going to rely on repeated addition of irrational numbers to come out to some exact value, then you've misunderstood the abilities of finite decimal representations. It is something easy to overlook, but shouldn't be too surprising to someone who has computed any…

We can do better. It's true that decimal representation doesn't work:

    0.999999 = 0.142857 + 0.142857 + 0.142857 + 0.142857 + 0.142857 + 0.142857 + 0.142857 
And yes, rewriting the problem in an integer-indexed form does get the correct result:

    1 = (1 + 1 + 1 + 1 + 1 + 1 + 1) / 7
But what we want, in both the original code and in this example, is to calculate:

        1   1   1   1   1   1   1
    1 = — + — + — + — + — + — + —
        7   7   7   7   7   7   7
That's even hard to type out in our limited format here on HN. But it's what we mean to do.

Maybe better tooling could infer that if the limited math produces an angle indistinguishably close to 2pi, we probably meant for it to be equal to 2pi. Maybe it could do fractional addition, instead of converting to a decimal representation and truncating the number of digits.

Maybe it would write the outputs of the function in the initial triangle example, instead of as

    ([50 0]
     [-24.99999999999999 43.30127018922194]
     [-25.00000000000002 -43.301270189221924])
it would be represented as

    ([50 0]
     [-25 25*sqrt(3)]
     [-25 -25*sqrt(3)])
Because the sine of 2pi/3 is sqrt(3)/2, not 0.866.

Re: Island Generator

#29

Really cool! beyond the generation, I learned about https://github.com/viebel/klipse which looks pretty cool. The whole post also makes me want to look more into clojure. Aside: Is it OK to not have a element?

Yep, you don't need a head — browsers will handle that just fine, and the spec generally allows for it. For an example of some HTML that leans quite heavily on the ability to omit tags, see here: http://www.colorglare.com/2014/11/24/stateless-html.html

And you should get into Clojure(Script). It's a joyful language.

Post reply on HN