cragwolf
19-11-2006, 08:06 AM
I was reading an online book (http://www.maths.manchester.ac.uk/~avb/micromathematics/downloads) the other day, and came across a formula which gives the abs function (http://community.freepascal.org:10000/docs-html/rtl/system/abs.html) (absolute value of a number) in terms of the max function (http://community.freepascal.org:10000/docs-html/rtl/math/max.html) (the larger of two numbers):
abs(x) = max(x, -x)
So one step ahead I wondered if there was a formula which goes the other way: the max function in terms of the abs function. After much hair-pulling I managed to derive it:
max(x, y) = 0.5 * (x + y + abs(x-y))
Not as fast as the way it's normally done in code (or in our brains, for that matter):
if x > y then Result := x else Result := y;
But I thought it was pretty neat all the same. Moving on...
This thread (http://www.pascalgamedevelopment.com/viewtopic.php?t=3791) about tessellating spheres got me thinking, too. I wondered if the geosphere algorithm might produce a better sphere if one started from something somewhat more sphere-like than an octahedron. Enter the icosahedron, which has twenty faces, each face an equilateral triangle. But how do you draw an icosahedron?
Here's a simple technique, illustrated below (taken from the aforementioned book):
http://www.ludicity.org/images/icosahedron.png
Initially, draw an appropriately oriented line on each face of a cube. Then join the ends of each line together in an appropriate manner. The only tricky bit is knowing how long the initial lines are supposed to be. To guarantee equilateral triangles, I found after further hair-pulling that on a cube with sides of length D, the length of these initial lines must be:
L = 0.5 * D * (sqrt(5) - 1)
Or more simply:
L = D / G
where G is the well-known golden ratio (http://en.wikipedia.org/wiki/Golden_ratio), which has applications in art, music, and Egyptian pyramids!
Mathematical recreation is not a bad hobby if you don't mind baldness.
abs(x) = max(x, -x)
So one step ahead I wondered if there was a formula which goes the other way: the max function in terms of the abs function. After much hair-pulling I managed to derive it:
max(x, y) = 0.5 * (x + y + abs(x-y))
Not as fast as the way it's normally done in code (or in our brains, for that matter):
if x > y then Result := x else Result := y;
But I thought it was pretty neat all the same. Moving on...
This thread (http://www.pascalgamedevelopment.com/viewtopic.php?t=3791) about tessellating spheres got me thinking, too. I wondered if the geosphere algorithm might produce a better sphere if one started from something somewhat more sphere-like than an octahedron. Enter the icosahedron, which has twenty faces, each face an equilateral triangle. But how do you draw an icosahedron?
Here's a simple technique, illustrated below (taken from the aforementioned book):
http://www.ludicity.org/images/icosahedron.png
Initially, draw an appropriately oriented line on each face of a cube. Then join the ends of each line together in an appropriate manner. The only tricky bit is knowing how long the initial lines are supposed to be. To guarantee equilateral triangles, I found after further hair-pulling that on a cube with sides of length D, the length of these initial lines must be:
L = 0.5 * D * (sqrt(5) - 1)
Or more simply:
L = D / G
where G is the well-known golden ratio (http://en.wikipedia.org/wiki/Golden_ratio), which has applications in art, music, and Egyptian pyramids!
Mathematical recreation is not a bad hobby if you don't mind baldness.