POV-Ray : Newsgroups : povray.newusers : Help - very difficult when it should be easy : Re: Help - very difficult when it should be easy Server Time
29 Apr 2024 17:54:45 EDT (-0400)
  Re: Help - very difficult when it should be easy  
From: Bald Eagle
Date: 17 Nov 2016 13:05:01
Message: <web.582df094ba97f5c1b488d9aa0@news.povray.org>
Thanks Trevor.  :)

I _almost got it.
Still a bit hairy somewhere.

Here's what I'm trying to get to work:


#version 3.7;

global_settings {assumed_gamma 1.0}

#include "colors.inc"
#include "math.inc"
#include "rand.inc"
#include "textures.inc"
#include "transforms.inc"

#declare Feet = 12;
#declare Phi = (1+sqrt(5))/2;

camera {
 location <0*Feet, 0*Feet, -500*Feet>
 look_at  <0*Feet, 0*Feet, 0>
 right     x*image_width/image_height
 up y
}

light_source {<50*Feet, 5000*Feet, 10000*Feet> Yellow} // Sun
light_source {<-100*Feet, 50*Feet, -300*Feet> White}

sky_sphere{ pigment { gradient <0,1,0>
                      color_map { [0.00 rgb <0.6,0.7,1.0>]
                                  [0.35 rgb <0.0,0.1,0.8>]
                                  [0.65 rgb <0.0,0.1,0.8>]
                                  [1.00 rgb <0.6,0.7,1.0>]
                                }
                      scale 2
                    } // end pigment
          } //end skysphere

//###########################################################################################

#declare DrawingScale = 8*Feet / 25;
#declare ArcHeight = 18*DrawingScale; // measured 18 mm on drawing
#declare ArcLength = 170*DrawingScale; // measured 17 cm (170 mm) on drawing
#declare GlobeRadius = (pow(ArcHeight,2) + pow(ArcLength,2)) / (2*ArcHeight);

#declare Scale = GlobeRadius/Phi;   // radius of sphere
#debug concat( " GlobeRadius = ", str(Scale/12, 3, 2), " feet \n")

//###########################################################################################

#declare TwentyHedron = array [12] {
<0, Phi, -1>,   // Top front    0
<0, Phi,  1>,   // Top Rear     1

<-Phi,  1, 0>,  // Left Top     2
<-Phi, -1, 0>,  // Left bottom  3

<Phi,  1,  0>,  // Right top    4
<Phi, -1,  0>,  // Right bottom 5

<-1, 0, -Phi>,  // Front left   6
< 1, 0, -Phi>,  // Front Right  7

<-1. 0, Phi>,   // Rear left   8
< 1, 0, Phi>,   // Rear right   9

<0, -Phi, -1>,  // bottom front 10
<0, -Phi,  1>,  // bottom rear  11
}

#declare IcosahedralArray = array [20][3] {
 //front top cap
    {TwentyHedron[ 0], TwentyHedron[ 4], TwentyHedron[ 1]},     //          1
    {TwentyHedron[ 0], TwentyHedron[ 7], TwentyHedron[ 4]},     //        /   \
    {TwentyHedron[ 0], TwentyHedron[ 6], TwentyHedron[ 7]},     //       2  0  4
    {TwentyHedron[ 0], TwentyHedron[ 2], TwentyHedron[ 6]},     //       \     /
    {TwentyHedron[ 0], TwentyHedron[ 1], TwentyHedron[ 2]},     //        6---7
    // middle belt
    {TwentyHedron[ 1], TwentyHedron[ 9], TwentyHedron[ 8]},
    {TwentyHedron[ 1], TwentyHedron[ 4], TwentyHedron[ 9]},
    {TwentyHedron[ 4], TwentyHedron[ 5], TwentyHedron[ 9]},
    {TwentyHedron[ 4], TwentyHedron[ 7], TwentyHedron[ 5]},     //
1---4---7---6---2---1
    {TwentyHedron[ 7], TwentyHedron[10], TwentyHedron[ 5]},     //     / \ / \ /
\ / \ / \ /
    {TwentyHedron[ 7], TwentyHedron[ 6], TwentyHedron[10]},     //
8---9---5---10--3---8
    {TwentyHedron[ 6], TwentyHedron[ 3], TwentyHedron[10]},
    {TwentyHedron[ 6], TwentyHedron[ 2], TwentyHedron[ 3]},
    {TwentyHedron[ 2], TwentyHedron[ 8], TwentyHedron[ 3]},
    {TwentyHedron[ 2], TwentyHedron[ 1], TwentyHedron[ 8]},
    //rear bottom cap
    {TwentyHedron[11], TwentyHedron[ 8], TwentyHedron[ 9]},     //        8---9
    {TwentyHedron[11], TwentyHedron[ 9], TwentyHedron[ 5]},     //       /     \
    {TwentyHedron[11], TwentyHedron[ 5], TwentyHedron[10]},     //      3   11
5
    {TwentyHedron[11], TwentyHedron[10], TwentyHedron[ 3]},     //       \     /
    {TwentyHedron[11], TwentyHedron[ 3], TwentyHedron[ 8]}      //          10
}

//
################################################################################################

#macro Subdivision (BasisArray, Iterations)

 //-----------------------------------------------------------------
 //  Subdivision of triangles
 //-----------------------------------------------------------------
 #for (Subdivide, 1, Iterations)
 #local BasisNumber = dimension_size (BasisArray, 1);
 #local ExpandedArray = array [4 * BasisNumber][3];
 //#debug "------------\n"
     #for (BasisTriangle, 0, BasisNumber-1)

 //  Subdivision scheme for triangles
 //           1
 //          / \
 //         A___B
 //        / \ / \
 //       0___C___2

 #local Vertex_A = vnormalize(
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][1])/2 );
 #local Vertex_B = vnormalize(
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][2])/2 );
 #local Vertex_C = vnormalize(
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][0])/2 );

 #local ExpandedArray [(4*BasisTriangle)+0][0] =
vnormalize(BasisArray[BasisTriangle][0]);
 //#local ExpandedArray [(4*BasisTriangle)+0][1] =
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][1])/2;
 #local ExpandedArray [(4*BasisTriangle)+0][1] = Vertex_A;
 //#local ExpandedArray [(4*BasisTriangle)+0][2] =
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][2])/2;
 #local ExpandedArray [(4*BasisTriangle)+0][2] = Vertex_C;

 #local ExpandedArray [(4*BasisTriangle)+1][0] =
vnormalize(BasisArray[BasisTriangle][1]);
 //#local ExpandedArray [(4*BasisTriangle)+1][1] =
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][0])/2;
 #local ExpandedArray [(4*BasisTriangle)+1][1] = Vertex_B;
 //#local ExpandedArray [(4*BasisTriangle)+1][2] =
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][2])/2;
 #local ExpandedArray [(4*BasisTriangle)+1][2] = Vertex_A;

 #local ExpandedArray [(4*BasisTriangle)+2][0] =
vnormalize(BasisArray[BasisTriangle][2]);
 //#local ExpandedArray [(4*BasisTriangle)+2][1] =
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][0])/2;
 #local ExpandedArray [(4*BasisTriangle)+2][1] = Vertex_C;
 //#local ExpandedArray [(4*BasisTriangle)+2][2] =
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][1])/2;
 #local ExpandedArray [(4*BasisTriangle)+2][2] = Vertex_B;

 //#local ExpandedArray [(4*BasisTriangle)+3][0] =
(BasisArray[BasisTriangle][0]+BasisArray[BasisTriangle][1])/2;
 #local ExpandedArray [(4*BasisTriangle)+3][0] = Vertex_A;
 //#local ExpandedArray [(4*BasisTriangle)+3][1] =
(BasisArray[BasisTriangle][1]+BasisArray[BasisTriangle][2])/2;
 #local ExpandedArray [(4*BasisTriangle)+3][1] = Vertex_B;
 //#local ExpandedArray [(4*BasisTriangle)+3][2] =
(BasisArray[BasisTriangle][2]+BasisArray[BasisTriangle][0])/2;
 #local ExpandedArray [(4*BasisTriangle)+3][2] = Vertex_C;

 /*
 #debug concat( "Vertex 0 = ", vstr(3, BasisArray[BasisTriangle][0], ", ", 3,
3), " \n")
 #debug concat( "Vertex 1 = ", vstr(3, BasisArray[BasisTriangle][1], ", ", 3,
3), " \n")
 #debug concat( "Vertex 2 = ", vstr(3, BasisArray[BasisTriangle][2], ", ", 3,
3), " \n")
 #debug concat( "Vertex A = ", vstr(3, Vertex_A, ", ", 3, 3), " \n")
 #debug concat( "Vertex B = ", vstr(3, Vertex_B, ", ", 3, 3), " \n")
 #debug concat( "Vertex C = ", vstr(3, Vertex_C, ", ", 3, 3), " \n")
 #debug "------------\n\n"
 */

 #end // end for BasisTriangle
 #local BasisArray = ExpandedArray;
#end // end for Subdivide

ExpandedArray

#end // end macro subdivision


//
################################################################################################

// Build Globe for Scene

#declare Globe_Array = Subdivision (IcosahedralArray, 4)  //  <=================
perform expansion of icosahedraal basis array
#declare ExpandedNumber = dimension_size (Globe_Array, 1);

 #for (Side, 0, ExpandedNumber-1)
  #for (Vertex, 0, 2)
   #declare Globe_Array[Side][Vertex] = Globe_Array[Side][Vertex] * Scale;
  #end // end for Vertex
 #end // end for Side

#declare Strut = 5;
#declare GlobeColor = pigment {Green*0.5}

//  Cylinder Mesh (as guide) and Struts
#declare MeshSphere_1 =
union {
 #declare LastVertex = <0, 0, 0>;

 #for (Side, 0, ExpandedNumber-1)
     #for (Vertex, 0, 2)
   #declare ThisVertex = Globe_Array[Side][Vertex];
   //#debug concat( "Vertex = ", vstr(3, ExpandedArray[Side][Vertex], ", ", 3,
3), " \n")

   #if (Vertex > 0)
    cylinder {LastVertex, ThisVertex, Strut/4 texture {pigment {GlobeColor}
finish {specular 0.8}} }
    #declare CurrentVector = (ThisVertex - LastVertex);

//--------------------------------------------------------------------------------------------------
      // #declare Vec = Point2 - Point1;       //Direction vector to orient to
      #declare Vec = (ThisVertex - LastVertex);
      #declare StrutLength = vlength(CurrentVector);  //LENGTH OF BOX
    //Twist rotates the box around the long axis first
    #declare Twist = 0;
      //RotZ and RotY reoorient the box to align to the vector
      #if (StrutLength = 0 | Vec.x = 0 | Vec.z = 0)
       // do nothing
      #else
       #declare RotZ = degrees(atan2(Vec.y, vlength(<Vec.x, 0, Vec.z>)));
//ROTATION ABOUT Z-AXIS
       #declare RotY = degrees(atan2(Vec.z, Vec.x));
//ROTATION ABOUT Y-AXIS

     #declare IBeam = union {
      box {<0, -Strut, -Strut/3>, <StrutLength, -Strut*0.9, Strut/3>}
      box {<0, -Strut, -Strut/2>, <StrutLength,  Strut,     Strut/2>}
      box {<0,  Strut, -Strut/3>, <StrutLength,  Strut*0.9, Strut/3>}
      pigment {Red*0.5}
     } // end IBeam

     // sphere {Point1 0.5 pigment {Orange*0.5} }
     // sphere {Point2 0.5 pigment {Violet*0.5} }

     #declare NewIBeam = object {IBeam
      rotate Twist*x
          rotate RotZ*z
          rotate RotY*y
     }

     object {NewIBeam translate ThisVertex}
    #end // end if (atan2 check)
   #end // end if (past 1st triangle point)

   #declare LastVertex = ThisVertex;
  #end // end for Vertex



   cylinder {LastVertex, Globe_Array[Side][0], Strut/4 texture {pigment
{GlobeColor} finish {specular 0.8}} }
   #declare CurrentVector = (Globe_Array[Side][0] - LastVertex);

//--------------------------------------------------------------------------------------------------
    // #declare Vec = Point2 - Point1;       //Direction vector to orient to
    #declare Vec = (ThisVertex - LastVertex);
    #declare StrutLength = vlength(CurrentVector);  //LENGTH OF BOX
   //Twist rotates the box around the long axis first
   #declare Twist = 0;
    //RotZ and RotY reoorient the box to align to the vector
    #if (StrutLength = 0 | Vec.x = 0 | Vec.z = 0)
     // do nothing
    #else
      #declare RotZ = degrees(atan2(Vec.y, vlength(<Vec.x, 0, Vec.z>)));
//ROTATION ABOUT Z-AXIS
      #declare RotY = degrees(atan2(Vec.z, Vec.x));
//ROTATION ABOUT Y-AXIS

    #declare IBeam = union {
     box {<0, -Strut, -Strut/3>, <StrutLength, -Strut*0.9, Strut/3>}
     box {<0, -Strut, -Strut/2>, <StrutLength,  Strut,     Strut/2>}
     box {<0,  Strut, -Strut/3>, <StrutLength,  Strut*0.9, Strut/3>}
     pigment {Red*0.6}
    } // end IBeam

    // sphere {Point1 0.5 pigment {Orange*0.5} }
    // sphere {Point2 0.5 pigment {Violet*0.5} }

    #declare NewIBeam = object {IBeam
     rotate Twist*x
         rotate RotZ*z
         rotate RotY*y
    }

    object {NewIBeam translate ThisVertex}
   #end // end if (atan2 check)
 #end // end for Side

} // end union MeshSphere_1


#declare Globe = union {
 object {MeshSphere_1}   // Struts

 #declare Axes = 12;
 cylinder {<0, 0, 0>, <200*Feet, 0, 0> Axes pigment {Red*0.5}}
 cylinder {<0, 0, 0>, <0, 200*Feet, 0> Axes pigment {Green*0.5}}
 cylinder {<0, 0, 0>, <0, 0, 200*Feet> Axes pigment {Blue*0.5}}
}


object {Globe}


Post a reply to this message

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