Friday, October 28, 2016

Function Junction

Due to still being ill, I've not made demonstrable progress on much of anything that I can show you. And between tiredness and illness, I can't really apply my mind to writing reviews on any of the books I've recently finished, although I shall mention that I've recent started reading Arch Whitehouse's The Zeppelin Fighters and find it engrossing.

One thing I did manage to complete was a very small program for function graphing.  I had some thoughts on using trigonemetric and other math functions, and combinations thereof, for various simulation or generation purposes.  Light levels and sun elevation for day/night cycles, terrain generation, and waves can all be modified with functions.

Absolute value of sine: y = abs(sin(x))
Sawtooth function: too messy for including in the caption, so see below.

private double Sawtooth(double x)


double a = 2;
double t = x;
double toa = t / a;
double y = 2 * ((toa) - Floor(toa + 0.5));
return y;

private double Clamp(double value, double low, double high)

if (value < low) return low;
if (value > high) return high;
return value;

Clamped sine:  y = clamp(sin(x), 0, 1)

None of these are likely to be original ideas, as I'm aware of some use of them for such purposes.For example, cosine is used for mountain ranges in the "River and Coastal Action" article I've mentioned before.  This tiny little program is helping me do a little visualization of how these functions work. There are math programs that can do this, I think (my TI calculator can do some of it), but whatever functions I come up with will have to be expressed in code anyway so I can use them in other code, so being able to quickly prototype is nice.

Some of the functions are useful in and of themselves, while otherwise would need to be combined with other techniques (such as noise) to be of use.  For now, though, I shall bid the world a fond goodnight and get some sleep.

No comments:

Post a Comment