Showing posts with label fractal. Show all posts
Showing posts with label fractal. Show all posts

Friday, June 3, 2016

Mandelbox Fractals and Flights

Deus Ex Machina – Example Mandelbox fractal image I created.
Deus Ex Machina – Example Mandelbox fractal image I created.


I’ve previously posted some images of Mandelbox fractals, so this time I’ll write more about them and provide a video I made of various flights through the Mandelbox.

The Mandelbox is a folding fractal, generated by doing box folds and sphere folds. It was discovered by Tom Lowe (Tglad or T’glad on various forums). The folds are actually rather simple, but surprisingly, produce very interesting results. The basic iterative algorithm is:

if (point.x > fold_limit) point.x = fold_value – point.x
else if (point.x < -fold_limit) point.x = -fold_value – point.x

do those two lines for y and z components.

length = point.x*point.x + point.y*point.y + point.z*point.z

if (length < min_radius*min_radius) multiply point by fixed_radius*fixed_radius / (min_radius*min_radius)
else if (length < fixed_radius*fixed_radius) multiply point by fixed_radius*fixed_radius / length

multiply point by mandelbox_scale and add position (or constant) to get a new value of point

Typically, fold_limit is 1, fold_value is 2, min_radius is 0.5, fixed_radius is 1, and mandelbox_scale can be thought of as a specification of the type of Mandelbox desired. A nice value for that is -1.5 (but it can be positive as well).

There’s a little more to it than that, but just as with Mandelbrot sets and Julia sets, the Mandelbox starts with a very simple iterative function. For those who are curious, the fold_limit parts are the box fold, and the radius parts are the sphere fold.

One of the parts that is left deals with what’s called ray marching. Since these types of fractals don’t have a simple parametric equation that can be easily solved without the need for iterations, etc., one must progress along the ray and ask “are we there yet?”. To help speed up this progression, an estimate of a safe distance to jump is calculated (using a distance estimator). Once the jump is made, the “are we there yet?” question is asked again. This goes on until either we get close enough or it’s clear we will never get there. The “close enough” part involves deciding ahead of time how precise we want the image to be. Since fractals have infinite precision/definition (ignoring the limitations of the computer, of course), there’s no choice but to at some point say “we’re close enough”. This basically means we’re rendering an isosurface of the fractal. To see what I mean, refer to both my “Deus Ex Machina” image and my “Kludge Mechanism” image. Kludge Mechanism uses a less precise setting and therefore has less features.
Kludge Mechanism – Example Mandelbox fractal image I created
Kludge Mechanism – Example Mandelbox fractal image I created

The ray marching technique (and distance estimator method) can be used to create a Mandelbulb, 4D Julia, Menger Sponge, Kaleidoscopic IFS (KIFS), etc. as well as non-fractal objects like normal boxes, spheres, cones, etc. But many of the non-fractal objects are better and faster calculated with parametric equations.

Now for the fun part (hopefully). Here’s a video I made using my raytracer. It shows various Mandelbox flights and even a section varying the mandelbox_scale from -4 to -1.5

One of the flights points out an interesting by-product of an attempt to speed up the ray marching. One can specify a bound radius in which anything outside of that radius doesn’t need to be run through the ray marching process. In my “Futuristic City Under Construction” flight, I accidentally set the bound radius too small which cut out some of the Mandelbox. But, in this case, it was, in my opinion, an improvement because it removed some clutter.
Futuristic City Under Construction (Small Bounding Radius)
Futuristic City Under Construction (Small Bounding Radius)
Futuristic City Under Construction (Correct Bounding Radius)
Futuristic City Under Construction (Correct Bounding Radius)


I’ve also created another video showing just Deus Ex Machina but with higher resolution, more detail, and more frames. Even though it’s 1080p, I recommend using the 720p setting.


And another video showing just Futuristic City Under Construction but with much better camera movements, further flight, more detail, more frames, and 16:9 aspect ratio.

To better view these videos on my YouTube channel (with full control) go to: http://www.youtube.com/MrMcSoftware/videos


A lot more can be said on the subject of Mandelbox fractals, as well as a lot more images I created, but this will do for now.

Thursday, March 27, 2014

My Hypothetical Day as a Substitute Teacher (aka Raytracing is Fun for Everyone)


A raytraced virtual art gallery I created using a raytracer I wrote. It includes drawings of girls I drew.
A raytraced virtual art gallery I created using a raytracer I wrote. It includes drawings of girls I drew
 

   I've often thought that if, for some reason, I ever ended up being a substitute teacher, I would offer the students a choice.  Do the boring assignment their normal teacher wanted them to do - and let's face it, nobody feels like doing that when the teacher's not around - or learn how to do what makes Pixar films, for example, possible.  Let's assume they chose the latter.  Then I would show them how to write a raytracer.  Of course, since, let's assume, this is not a computer programming class (in which case I would be preaching to the choir anyway), not everyone would know how to program a computer or know the language I would be using.  So, most of the stuff would have to be "spoon fed" to them.

  One might wonder, "Well then, what's the point?"  The point is that raytracing not only covers the subjects of computer programming, but also math, physics, art, language, and depending on how the raytracer is used, chemistry, biology, and many other fields.  So, hopefully, it would be a way of showing how all those subjects are actually useful in the real world.  And once the students see how easy it was, admittedly because of the spoon feeding mentioned earlier, and see the nice results, who knows what interests might be sparked.  Perhaps, unrealistic wishful thinking, but hey, no one wanted to do the assigned work anyway.  I bet the normal teacher and the administration wouldn't like me, but who knows.  Plus, I've read that the "new way" of teaching in this era of Google, smartphones, and spell check is "how to think" rather than just facts and dates.

   So, you might be thinking, "Ok, I'm sold, so what is raytracing?".  Well, imagine looking out your window, scanning every inch of your window as you look out at what's outside.  You see a car with shiny chrome with reflections of nearby objects.  And someone left a glass of water on the car.  You can see what's on the other side of the glass, through the glass and water - it looks distorted or bent.  You see shadows.  You see some parts of the car getting more sun than other parts.  In a sense, you've just raytraced.  What a raytracer does is send out mathematical rays of light out from the viewer's eye (or camera) through a screen (in the mathematical sense) searching for the nearest object (in the virtual scene) in the ray's path.  When a ray hits an object that is reflective and/or refractive it uses the law of reflection and Snell's Law to determine how the ray is to be altered. These laws are two of those things in Physics class you thought you would never see again.  Once the ray is altered in the appropriate manner, it once again searches for the nearest object in its path, until there's nothing left in its path, or a limit of how much to search is reached. That covers computer programming (the raytracer has to be coded in some computer language), math (the calculations), and physics (the laws of light rays).

   Now for the other subjects.  The obvious connection to art is color.  In computer monitor terms, for example, every color is really a combination of the right amounts of red, green, and blue.  In computer printer terms, every color is a combination of yellow, cyan, and magenta.  This difference has to do with whether the medium is additive or subtractive.  For raytracing, though, red, green, and blue are used.  There are other color models which make calculating colors easier.  For example, in many of my raytraced scenes that appear on my websites, I used the Hue, Saturation, and Value color model to add a gradual progression of colors through the spectrum.  I also like the look of metal, so many of my scenes have a metallic look. This would involve art (color of certain metals) but also physics again (light characteristics of metals).  Art is also applicable to the building of complex looking objects using a combination of simple objects.  For example, in its simplest form, a car can be made from a box and four circles.  Not a very good looking car, but everyone could imagine it's a car.  Put in a few more boxes, some tori (doughnuts), some cylinders, and probably some spheres (balls), and it starts to look more like a car.  Language comes into play here.  You have to have some way of specifying the scene.  Box would be a noun.  White, for example, would be an adjective.  Other scripting constructs could be thought of as verbs.  I realize this is stretching it a bit to say that this would help with grammar, but it does emphasize the importance of adjectives and nouns.

   Chemistry comes into play as one of the uses of raytracing, in the form of modeling complex (or simple) molecules.  As anyone who's seen a Pixar film would know, the characters in the film move (usually) in a human manner.  The human skeletal system is studied to make the characters walk in a more believable manner.  Thus, biology comes into play.  The method of raytracing has even been applied to sound instead of light, to model how sound propagates through a hallway, window, door, etc. and bounces off walls.

   Raytracers can range from the very simple to the very complex.  I've even seen a raytracer's code printed on a business card.  That shows how simple a raytracer can be to write (of course, any raytracer that short would be very limited and not very useful).  I wrote my raytracer on my Commodore Amiga computer but I would often run it on a SUN Workstation (UNIX) because my Amiga wasn't fast enough for complex scenes.  I eventually ported my raytracer to MS-DOS, Windows, and Linux / X-Windows.  It's come a long way throughout the years.  It didn't take years to write, of course; I did many other things between my excursions with my raytracer.

   In case you're sold on raytracers but not on writing your own, there are plenty of commercial and free raytracers.  POV-Ray being an excellent free one.  Well, happy raytracing!

A raytaced set of colored glass Moebius rings. Follow the color coding to see the twisting of the big ring.
A raytaced set of colored glass Moebius rings. Follow the color coding to see the twisting of the big ring.
A raytraced colored glass integrated circuit mask layout of a NAND logic circuit made from a gate array.
A raytraced colored glass integrated circuit mask layout of a NAND logic circuit made from a gate array.


A raytraced printed circuit board (PCB)
A raytraced printed circuit board (PCB)
A raytraced Mandelbox fractal
A raytraced Mandelbox fractal
A raytraced Mandelbox fractal.
A raytraced Mandelbox fractal.
A raytraced gold 4d quaternion Julia fractal
A raytraced gold 4d quaternion Julia fractal
Different ways of showing an ATP molecule using raytracing
Different ways of showing an ATP molecule using raytracing

I created many raytracing videos. Here is one of them. Go to http://youtube.com/mrmcsoftware/videos for more videos.