POV-Ray : Newsgroups : povray.binaries.scene-files : Polyhedra include file : Re: Polyhedra include file Server Time
2 Sep 2024 14:15:19 EDT (-0400)
  Re: Polyhedra include file  
From: Dan Johnson
Date: 19 Jan 2001 02:17:22
Message: <3A67EB4C.EFE1B3BD@hotmail.com>
Tor Olav Kristensen wrote:

> Dan Johnson wrote:
> >
> > #macro Arrange_3d (A,B,C,N)
> >        ( (mod(N+A-1,A))*x + (B-mod(div(N+A-1,A)+B-1,B))*y +
(mod(div(N+B*A-1,B*A)+C-1,C))*z -<A-1,B+1,C-1>/2)
> > #end  // use only natural numbers aka 1,2,3,4,5,6... no fractions 0 or negative
numbers
> >...
>
> A little nit-picking from me follows ...
>
> The above macro could be slightly simplified like this:
>
> #macro Arrange_3d(A, B, C, N)
>   (< mod(N+A-1,A),
>     -mod(div(N+A-1,A)+B-1,B),
>      mod(div(N+B*A-1,B*A)+C-1,C)>-
>    <A-1,-B+1,C-1>/2)
> #end // macro Arrange_3d
>
> Or like this:
>
> #macro MM(M,N)
>   mod(N+M-1,M)
> #end // macro MM
>
> #macro DD(M,N)
>   div(N+M-1,M)
> #end // macro DD
>
> #macro Arrange_3d(A,B,C,N)
>   (<MM(A,N),MM(B,DD(A,N)),MM(C,DD(A*B,N))>-<A-1,B-1,C-1>/2)*(x-y+z)
> #end // macro Arrange_3d
>

I think it took me three days to figure out how to make that macro work.  After that I
didn't want to look at it anymore.  Do you
understand what it does, and how?

This function started when I made my fist cube out of cylinders, and I looked at the
resulting points.
<0,0,0>
<0,0,1>
<0,1,0>
<0,1,1>
<1,0,0>
<1,0,1>
<1,1,0>
<1,1,1>

Hmm binary.  So I made a little macro based on base10 to binary conversion.

//macro Cube_points returns a vector for a corner of a cube given an integer 1-8
periodic after 8
#macro Cube_points (N)
        (mod(N,2)*2*z + mod(div(N+1,2),2)*2*y + mod(div(N+3,4),2)*2*x -1)
#end

Then I realized that it could be made much more versatile, and I set out to make a
cubic lattice of any dimensions.  Since the
order of placement was still based on my binary algorithm it arranged things in a way
people don't usually think.  I changed
things around until it went left to right, top to bottom, front to back ( like a
book).  The arrange 3d function is the result.

More recently I figured out that it could be made even more versatile.  I could do
things like have three in one row, and four in
the next, and continue alternating.  I think I may be able to make a macro that will
spit out the coordinates of icosahedron
vertexes.  That would go a long way towards simplifying the process of making an 8
frequency geodesic dome.

>
> > #declare Golden2 = (Golden -1); // the golden ratio is the only ratio where one is
the difference between it and its inverse
>
> I didn't know that. Interesting fact.
>
> It's a lot of math work you have done with this include !
>
> Maybe you could make some more general macros that
> handles arrays containing the coordinates for the
> different cylinders, spheres, torii and planes and
> then "spreads" them around to their positions ?
>
> E.g.
> If you declared and array like this:
>
> #declare IcosahedronVertexArray =
> array [12] {
>   < Golden2,        0,  Golden3>,
>   < Golden2,        0, -Golden3>,
>   < Golden3,  Golden2,        0>,
>   < Golden3, -Golden2,        0>,
>   <       0,  Golden3,  Golden2>,
>   <       0,  Golden3, -Golden2>,
>   <       0, -Golden3,  Golden2>,
>   <       0, -Golden3, -Golden2>,
>   <-Golden3,  Golden2,        0>,
>   <-Golden3, -Golden2,        0>,
>   <-Golden2,        0,  Golden3>,
>   <-Golden2,        0, -Golden3>
> }
>
> Then you could write things like this:
>
> #include "glass.inc"
>
> #declare SphereCentreArray =
>   ScaleArray(IcosahedronVertexArray, 3);
>
> #declare SphereRadii = 0.5;
>
> merge {
>   SphereSpread(SphereCenterArray, SphereRadii)
>   interior { I_Glass }
>   texture { T_Glass3 }
> }
>
> The ScaleArray macro just multiplies every
> vector in the array by a scalar.
>
> And the SphereSpread macro just puts a sphere
> in every position given in the array.
>

Didn't understand how the array function worked, makes sense now.

>
> I hope this triggers some ideas...  :)
>

It has.

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

Dan Johnson


Post a reply to this message

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