POV-Ray : Newsgroups : povray.binaries.images : Inside the Crackle pattern (161KB) : Re: Inside the Crackle pattern (161KB) Server Time
3 May 2024 20:48:19 EDT (-0400)
  Re: Inside the Crackle pattern (161KB)  
From: Tor Olav Kristensen
Date: 23 Oct 2000 20:37:31
Message: <39F4D9AD.3F6B2F20@online.no>
SomeGuy wrote:

> i DL the source but i do not understand the if statement you referred to
> ...
>
> I let the iso-surface do the work itself.
> (-By using a pigment function inside an if statement. If the pigment
> value in the middle of a "subcube" in 3D-space is above a certain
> limit/threshold, a function is called to make a sphere in this
> "subcube".
> Else a constant outside the limit is returned.)
>
> What does this statement exactly do... Or better yet how does it do what
> it does...
> How are the arguments read...?
>
> if(
>       MidOfCrackleSquare(x, y, z) - Threshold,
>       ManySpheres(x, y, z),
>       1
>     )
>
> Im guessing if mid of crackle square... then do many spheres... what is
> the 1... threshold...?
> please help,

I find this difficult to explain, but I'll give it a try.

Here I go:
(Anyone please correct me if I'm telling any lies here.)

For "every" point inside the contained_by shape, find out which
cube in 3D-space this point is contained within.
(E.g. The point <3.4, 7.8, 0.1> is contained within the cube
with opposite corners <3, 7, 0> and <4, 8, 1>.)

Find the middle of this cube and fetch the field strength for the
crackle pattern at that midpoint. (E.g.: The midpoint of the cube
above is <3 + 0.5, 7 + 0.5, 0 + 0.5> = <3.5, 7.5, 0.5>)

(The MidOfCrackleSquare function calculates the coordinates
for these midpoints. {A better name for this function would have
been MidOfCrackleCube.} The MidOfCrackleSquare calls the
CrackleFunction and passes the midpoint to it. The
CrackleFunction returns the "field strength" value at this point.)

Then the field strength is checked if it is above a certain
"Threshold" limit. If it is, then the point belongs to a set of points
that "later" will be evaluated as candidates for being inside a
sphere within the cube.

All such points that are found to be inside such a cube with
an "OK" threshold in it's middle are evaluated with the
ManySpheres function.

If they are found to be inside a cube with a "wrong" threshold
in its middle, they are "assigned" with a value that guarantees
that they are not candidates for being considered as "insiders"
to the isosurface.

The ManySpheres function translates the point given it
to a corresponding position within a similar cube centred
around origo.

Then the ManySpheres function calls the built in "sphere"
function that calculates how far the translated point is from
the surface of a sphere centred around origo. (It returns
positive values if the translated point are outside the sphere.
0 if it's on the sphere's surface, and negative values if it's inside
the sphere.)

The result of this is that the original point is assigned the same
value as it's translated version.

One can imagine that after "all" points inside the contained_by
shape have been evaluated, they have been assigned a value
that now are checked to see if they are inside, outside or on
the isosurface.

All the points that was not assigned a "guaranteed not insiders"
value, are now candidates for being _on_ the isosurface or
inside it.

The float after the isosurface's threshold keyword gives the
potential that the value of every such points is checked against.

If a point has an "assigned" value that is equal to this potential,
then it is _on_ the isosurface. If its value is greater than this
potential, then the point is outside the isosurface, and if its value
is less than this potential, then the point is inside the isosurface.

So if the isosurface shape is not involved in any CSG-operations
then only the points that are _on_ the isosurface are "visible".


Notes:

To find the radii of the spheres in the image, just add the
the value after the threshold keyword (0.2) to the radius
given to the built in function "sphere" (0.2). Thus the radius
of all the spheres are 0.4.

To find a suitable value to be assigned to "guaranteed not
insiders" points, one can select a value just above the value
after the threshold keyword (0.2). I had not reflected much
about this, so I chose the value 1. (0.21 would have been
sufficient.)


Feel free to ask more if there's anything that needs more
explaining.

Below are some code made for playing around with my
ManySpheres function.

P.S.:
Try to uncomment the commented lines different combi-
nations (At different resolutions and AA settings)

Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version unofficial MegaPov 0.5;
#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare SphereFunction = function { "sphere" <0.1> }

#declare ManySpheres =
function {
  SphereFunction(
    x - floor(x) - 0.5,
    y - floor(y) - 0.5,
    z - floor(z) - 0.5
  )
}

isosurface {
  function { ManySpheres(x, y, z) }
//  threshold 0.1
  contained_by { sphere { <0, 0, 0>, 200 } }
//  method 1
  pigment { color Yellow }
  no_shadow
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color Blue/2 }

//light_source { 1000*<-3, -4, 2> color White*2 }
light_source { 1000*<0, 1, 0> color White*2 }

camera {
  location <0, 0, -10.5>//*60
  look_at <0, 0, 0>
//  angle 35
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.