|
If you have taken any interest in the subject of fractals, you will be aware
of Sierpinsky's triangle. Take any three fixed points to define a triangle and any other point to start. Then
repeat the following two steps ad nauseum:
* Choose one of the fixed points on a random basis
* Move halfway towards it for your next point and plot it. This will fill in series of triangles, halving in
size as they move to each of the corners. The pattern is self-similar at all scales, the essence of a
fractal.
Doubtless, Mr Sierpinsky was aware that this works equally well in three dimensions with four points defining
a tetrahedron - hence the above title to pay due deference. Whilst I haven't seen any attempts to depict this
in viewable stereo, someone probably has done so and I am happy to be second, or umpteenth. Using the mirror
technique which I attempt to popularise, this can be done with a short and simple QBasic program as below.
The diagram looks like "three-pennorth of God 'elp us", as my dear grandmother used to say, unless you bother
to find a piece of mirror.
(Here we go again. Mirror 30 cm or so wide [15-45 OK]. One side on centre line with mirror facing left and at
right angles to page, or screen. Nose on other side. Right eye looks at right screen. Left eye looks towards
right screen but sees reflection of left screen. Lo, perfect stereo.)
We'll refer to our first tetrahedron as TH.
Note the four half-scale tetrahedra (TH/2) near each corner, with one-eighth the volume of TH, leaving a
completely vacant space in the centre which is half the volume of TH. Each TH/2 has four TH/4 near each
corner with a half volume empty space in the middle. This continues down to infinitesimally small dimensions,
so that the whole TH is really empty space occupied by zero-dimension points - which makes it an ideal stereo
subject as we can see through it, except that our pixels do occupy some space.
In the code, we remember the last four corners aimed at, and add their numbers to get the colour to use for
each point. For example, if it happens that a row of corner 0 comes up, the point would be in the TH/16 in
the corner 0 and it would be coloured black (0). A string of 3s would give a light red (12) point in the
TH/16 in the 3 corner. Fortunately, this also works in the interior so that every TH/16 (which is not empty
space) consistently gets its allotted colour from the range 0 - 12; nifty, huh? Before plotting any point, we
check that both left and right pixels are still white and don't plot either if either is already occupied;
this gives a clearer result as there aren't any pixels without their stereo mates.
Do tap the code into your QBasic to see it on-screen where it is vastly superior to the printed version. You
can omit the comments if you are bone idle like me. If you are incorrigible, it can be downloaded as SIERPINS.LZH. While you are there, if you haven't already tried Fractint, pull down FRAIN195.ZIP (DOS, 589 KB, v19.5, Apr 97) or WINF1821.ZIP
(Win, 495 KB, v18.21, May 96) to experience a thorough collection of fractals produced for your (free)
delectation by a large group of enthusiasts who are mostly professional programmers. It is far from an
amateur production but is not over-challenging to use.
DEFINT I-J 'some integer variables
'use VGA, 640x480 and put origin at centre.
SCREEN 12: CLS : WINDOW (-320, -240)-(319, 239)
LINE (-320, -240)-(319, 239), 15, BF 'white backgr.
LINE (0, -240)-(0, 200), 0 'black centreline
'4 points, 0, 1, 2 & 3. All on right screen
x(0) = 280: y(0) = -210: z(0) = -100
x(1) = 30: y(1) = 230: z(1) = 0
x(2) = 20: y(2) = -140: z(2) = 150
x(3) = 290: y(3) = 100: z(3) = 300
px = x(0): py = y(0): pz = z(0) 'starting point
rex =
80
'right eye at x= 80
lex =
-80
'left eye at x=-80
bey =
0
'both eyes at y= 0
bez =
-1000
'both eyes at z=-1000
start =
TIMER
'read time
FOR j = 1 TO 30000 'plot
30000 points
i = INT(RND *
4) 'corner
0,1,2,or 3
k = i + i2 + i3 + i4 'for
colour scheme
'move halfway towards chosen
corner...
px =(px+x(i))/2: py =(py+y(i))/2: pz =(pz+z(i))/2
'...and plot point for stereo view using mirror
fz = pz / (pz - bez) 'z factor for
stereo
'Now, using similar triangles in side view...
yb = (1 - fz) * py 'screen y,
both l&r
'And, similar triangles in plan
view...
xr = px - fz * (px - rex) 'screen x, right
xl = -(px - fz * (px - lex)) 'screen x, left
'note xl was mirror flipped to left screen
'Now, avoiding overplotting previous points,
IF POINT(xl, yb) = 15 AND POINT(xr, yb) = 15 THEN
PSET (xl, yb), k 'plot left
& right...
PSET (xr, yb), k 'points using colour
k
END IF
i4 = i3: i3 = i2: i2 = i remembers last three
NEXT
PRINT TIMER - start '10 secs on 66 MHz 486
DO: LOOP WHILE INKEY$ = "" 'look at it - Cheerio
|
Reprinted from the February 1999 issue of PC Update, the magazine of Melbourne PC User Group,
Australia
|