Ex Nihilo

A Processing Sketch Blog

Archive for the ‘Math’ Category

Bring on the Trig

Monday, August 17th, 2009

2Π. Pythagorean. SOH CAH TOA. Conjures up terms of grade 10, doesn’t it? I had to go waaay back into the memory banks to even pull out a starting point for a recent trigonometry refresher.

It started like this: I had an idea to plot some points on a sphere. Now, I understand with some crafty use of the rotate() function I’d probably be able to get by without doing the math myself, but I guess I had the urge to dig a bit deeper in case I need to really know this (again) at some point.

So I started light and plotted some random points around a circle. By setting the X coordinate, I can reverse the Pythagorean equation enough to work out the math for the Y coordinate:


  X = random(0 - radius, radius);
  Y = sqrt(pow(radius, 2) - pow(X, 2));

That only gets me a positive value for Y though, which renders as a semicircle. So a bit more randomization was necessary to get the full circle:


  int rev = int(random(0, 2));
  if (rev == 1) {
    Y = sqrt(pow(radius, 2) - pow(X, 2));
  } else {
    Y = 0 - sqrt(pow(radius, 2) - pow(X, 2));
  };

Which doesn’t strike me as terribly elegant, but that’s about the limit of my coding ability.

Random Point Circle

So that was the start. Now that I can plot individual points around a circle, why not use something other than points? With some fairly basic box() objects and various rotations and transformations, things get interesting quickly:

screencap-919
screencap-9836
screencap-6176
screencap-6965
screencap-2446
screencap-5530
screencap-6119
screencap-7964

I still haven’t gotten the math for the sphere down yet, though. That was a “walk away for now, and come back to it in a few days” type of problem.

Posted in Math | 2 Comments »