|
|
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I _ALMOST_ got it to work. It starts to spazz when I tell it to do 3 Reps.
> 1 Rep = 1 island
> 2 Reps = 6 islands around that - OK
> 3 Reps = 12 islands around those 7. But every other one is off.
> It makes me sad.
>
> In macro FullIsland put "yes" as the last argument to show all levels of
> subdivision.
>
> There's probably a better, more elegant way, but this is what I've come up with
> so far:
>
> //####################################################################
>
>
> #version 3.7;
>
> global_settings { assumed_gamma 1.8 }
>
> #include "colors.inc"
> #include "math.inc"
> #include "transforms.inc"
>
> light_source { <0.0, 0.0, -10.0> rgb 1 }
>
>
> #macro vec2rot(V, A)
> #local _X_ = V.u*cos(A) - V.v*sin(A);
> #local _Y_ = V.u*sin(A) + V.v*cos(A);
> #local RESULT = <_X_,_Y_>;
> RESULT
> #end
>
> /*
> #macro gosper_axiom(p0, p1)
> cylinder { p0, p1 0.02 }//cylinder { p0, p1 0.0078125 }
> #local V = p1 - p0;
> #local vT = vnormalize(V);
> #local len = vlength(V);
> #debug concat("len: "str(len,0,6) "\n")
> #debug concat("vTlen: "str(vlength(vT),0,6) "\n")
> #debug concat("newlen: " str(len/sqrt(7),0,6) "\n")
> #local np1 = p0 + len/sqrt(7)*vec2rot( vT,asin(sqrt(3)/(2*sqrt(7))));
> #local np2 = p1 - len/sqrt(7)*vec2rot( vT,asin(sqrt(3)/(2*sqrt(7))));
> #debug concat("np1: " vstr(2, np1,", ",0,10) "\n")
> #debug concat("np2: " vstr(2, np2,", ",0,10) "\n")
> union {
> cylinder { p0, np1 0.02 }
> cylinder { np1, np2 0.02 }
> cylinder { np2, p1 0.02 }
> pigment { Red }
> finish { ambient 0 diffuse 0.7 }
> }
> #end
> */
>
>
> #macro gosper_axiom_r(p0, p1, N, DrawAllLevels)
>
> #if (N >= 1)
> #if (DrawAllLevels)
> cylinder { p0, p1 0.002*Rep*N pigment {color srgbft CHSV2RGB(<(360/N), 1,
> 1>)} }
> #elseif (N=1)
> cylinder { p0, p1 0.002*Rep*N pigment {color srgbft CHSV2RGB(<(360/N), 1,
> 1>)} }
> #end
> #local V = p1 - p0;
> #local vT = vnormalize(V);
> #local len = vlength(V);
> #local np1=p0+len/sqrt(7)*vec2rot( vT,asin(sqrt(3)/(2*sqrt(7))));
> #local np2=p1-len/sqrt(7)*vec2rot( vT,asin(sqrt(3)/(2*sqrt(7))));
>
> gosper_axiom_r(p0, np1, N-1, DrawAllLevels)
> gosper_axiom_r(np1, np2, N-1, DrawAllLevels)
> gosper_axiom_r(np2, p1, N-1, DrawAllLevels)
> #declare N = N-1;
> #end
> #end
>
> #declare TH = degrees( asin( sqrt(3)/(2*sqrt(7)) ) );
> #declare L = 6.0/sqrt(7);
> #debug concat("L: " str(L,0,6) "\n")
> #debug concat("TH: " str(TH,0,6) "\n")
>
>
> //####################################################################
> #macro FullIsland (BeginSegment, EndSegment)
> #for (i, 1, 6)
> gosper_axiom_r(Endpoint1, Endpoint2, 4, no)
>
> // Rotate endpoints
> #declare RotatePoint = transform { rotate <0, 0, 60> }
> #declare Endpoint1 = vtransform (Endpoint1, RotatePoint);
> #declare Endpoint2 = vtransform (Endpoint2, RotatePoint);
> //#debug concat("Endpoint1: " vstr(2, Endpoint1,", ", 2, 1) "\n")
> //#debug concat("Endpoint2: " vstr(2, Endpoint2,", ", 2, 1) "\n")
> #end
> #end // end macro
> //####################################################################
>
>
> #declare Rep = 3;
> #declare Center = <0, 0, 0>;
> sphere {Center 0.1 pigment {Red}}
> #declare Y1 = Center.y+sqrt(3)/2;
> #declare Y2 = Center.y+sqrt(3)/2;
> #declare X1 = Center.x-0.5;
> #declare X2 = Center.x+0.5;
> #declare Endpoint1 = <X1, Y1, 0>;
> #declare Endpoint2 = <X2, Y2, 0>;
> //#debug concat("Endpoint1: " vstr(2, Endpoint1,", ", 2, 1) "\n")
> //#debug concat("Endpoint2: " vstr(2, Endpoint2,", ", 2, 1) "\n")
> FullIsland (Endpoint1, Endpoint2)
>
>
> //####################################################################
> //Automatically move camera back far enough
> camera {
> perspective
> location <0.0, 0.0, -3*Rep>
> up y
> right x*(image_width/image_height)
> look_at <0.0, 0.0, 0.0>
> }
>
>
> #if (Rep > 1)
> #for (j, 2, Rep)
> #declare NewCenter = <0, sqrt(3)*(j-1), 0>;
> #declare Y1 = NewCenter.y+sqrt(3)/2;
> #declare Y2 = NewCenter.y+sqrt(3)/2;
> #declare X1 = NewCenter.x-0.5;
> #declare X2 = NewCenter.x+0.5;
> #declare Endpoint1 = <X1, Y1, 0>;
> #declare Endpoint2 = <X2, Y2, 0>;
> #debug concat("j: " str(j, 0, 0) "\n")
>
> #for (k, 1, j*6)
> #debug concat("k: " str(k, 0, 0) "\n")
> FullIsland (Endpoint1, Endpoint2)
> #declare RotateCenter = transform { rotate <0, 0, 360/((j-1)*6)> }
> #declare NewCenter = vtransform (NewCenter, RotateCenter);
> #declare Y1 = NewCenter.y+sqrt(3)/2;
> #declare Y2 = NewCenter.y+sqrt(3)/2;
> #declare X1 = NewCenter.x-0.5;
> #declare X2 = NewCenter.x+0.5;
> #declare Endpoint1 = <X1, Y1, 0>;
> #declare Endpoint2 = <X2, Y2, 0>;
> //#debug concat("Endpoint1: " vstr(2, Endpoint1,", ", 2, 1) "\n")
> //#debug concat("Endpoint2: " vstr(2, Endpoint2,", ", 2, 1) "\n")
> #end // end k loop
>
> #end // end J loop
> #end // end if Reps
>
>
> //gosper_axiom(<-3.0, 0.0>, <-0.7014146472, 0.7014146472>)
wow... I didn't mean rewrite it. I need to use regular math because I'm refining
calculations for a c++ project I'm working on.
As for the math, the only assumption I used was that the outer radius of the
hexagons was 1 unit. Because a regular hexagon is composed of six equilateral
triangles, I could infer the other angles from bisection.
So most of it was geometry, really.
I'd say what I'm aiming for eventually, but then someone here would beat me to
it, and I really dislike that.
you're disturbingly close as it is.
Regards,
A.D.B.
Post a reply to this message
|
|