D. Edward Mitchell 16:00, 14 April 2020 (UTC) Hello World!    groupKOS Developer Share —usually UNDER CONSTRUCTION

3-group 13-8 orthogonal torus knots

From groupKOS Developer Share
Jump to navigation Jump to search

edit template POV-Ray code (potentially a lot coming someday —bucket list timing)
Macros | Scenes | Frames | Renderings | Animations | Tools

Ring amp 13-8 orthogonal torus knots phase-A 1024x768.png Ring amp 13-8 orthogonal torus knots phase-AB 1024x768.png Ring amp 13-8 orthogonal torus knots phase-ABC 1024x768.png

Persistence of Vision Ray Tracer (POV-Ray) torus knot source code

// Persistence of Vision Ray Tracer Scene Description File
// File: Groupkos.dev.ring_amp_phase-A_orthogonal_13-8_torus_knots_1024x768.png
// Vers: 3.7 RC7 win64
// Desc: 3-phase 13:8 torus knots as copper tubing.
// Date: May 1, 2013
// Auth: DonEMitchell (C) 
// March 9, 2020: Revisited and reorganized for posting at groupkos.com/dev/category:povray.

// Place these characters (without comment slashes) into the command line edit box to activate clocked frames.
// +SF1 +EF3 +KFI1 +KFF3  +W1024 +H768      

#version 3.7;

#include "colors.inc"
#include "golds.inc"
#include "metals.inc"
#include "transforms.inc"
#include "glass.inc"
//#include "push-pull_suspension.inc.pov"

global_settings {
    max_trace_level 10 // Reflection levels before blackness.   
    assumed_gamma 1.2
    charset utf8
    // used in global_settings, sets an overall brightness/ambient light level in the scene
    ambient_light color rgb <1,1,1> * 1
    } 
#default{ finish{ ambient 0.00125 diffuse 0.9 }} 

// ----------------- Optics --------------------
  
/* 
// Clocked zoom to a fisheye lens perspective, from inside the torus //
#declare cameraVector       = <-1,0,0>;
#declare cameraDistance     = -1;
#declare cameraViewAngle    = 170*clock;  //Fisheye perspective.
*/                                                                                             

#declare cameraDistance     = 29;       // 1920x1080 slanted orthogonal torus knot.
//#declare cameraDistance   =  3;       // 1920x1080 center close-up.

#declare cameraViewAngle    = 54;       // Normal perspective.                                                                 
#declare cameraVector =     <-1,0,0>;   // Where the camera is located.
//#declare cameraVector =     <-1,1,.50>;

#declare cameraLocation = cameraVector*cameraDistance;
#declare cameraLook_At = <0,0,0>;

// #declare consoleTextZoom = 1.325;  // 800x600   3:2    // Used in consoleObject().  Sizes text area to screen area. 
   #declare consoleTextZoom = 1.35; // 1024x1768  3:2    // Used in consoleObject().  Sizes text area to screen area. 
// #declare consoleTextZoom = 1.765; // 1920x1080  3:2    // Used in consoleObject().  Sizes text area to screen area. 
// #declare consoleTextZoom = 2.00765; // 1920x1080  3:2    // John Wsol.

#declare cameraAspectRatio = image_width/image_height;

#declare cameraSky = y;        
#declare cameraDirection=vnormalize(cameraLook_At-cameraLocation);      
#declare cameraRight=vnormalize(vcross(cameraSky,cameraDirection));     // to the right
#declare cameraUp=vnormalize(vcross(cameraDirection,cameraRight));      // camera up
    
camera { 
    //orthographic
    angle cameraViewAngle
    direction cameraDirection
    right cameraRight*cameraAspectRatio
    up cameraUp
    sky cameraSky
    location cameraLocation 
    look_at  0    
}    

#declare cameraTransform =                                              // A vector toward the camera from the origin.
    transform { matrix < 
                    cameraRight.x, cameraRight.y, cameraRight.z,
                    cameraUp.x, cameraUp.y, cameraUp.z,
                    cameraDirection.x, cameraDirection.y, cameraDirection.z,
                    cameraLocation.x, cameraLocation.y, cameraLocation.z
                >
    }

// Define a text-positioning-macro for console text based on camera location (adapted from screen.inc) for facing console text toward the camera. 
#macro consoleObject (Object, Position, Spacing, Confine, Scaling)
   #local Obj_Max = max_extent(Object);
   #local Obj_Min = min_extent(Object);
   #local Obj_Cen = (Obj_Max+Obj_Min)/2;
   #local Obj_Dim = (Obj_Max-Obj_Min)/2;
   #local Pos = (Position-0.5)*2;
   #local Pos = (
      +<Pos.x*cameraAspectRatio/2,Pos.y/2,consoleTextZoom>
      +( -Obj_Cen -Pos*(Obj_Dim+Spacing) ) * Confine
   );
   object {
      Object
      no_shadow     // shouldn't cast shadows in the scene
      no_reflection // shouldn't be reflected in scene elements
      translate Pos
      scale Scaling * 2 
      transform {cameraTransform} // rotate to face camera.
   }
#end
light_source { 
    cameraLocation
    color .9  
    shadowless
    //rotate z*10
    //rotate -x*40
    } 
light_source { 
    cameraLocation
    color 1
    shadowless
    rotate y*40
    rotate x*60
    }
    
sky_sphere{ pigment { gradient <-1,1,-1>
                      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 of pigment
}
              
//--------------------------- Macros --------------------------------- 
// Axes macro: length and radii of axes, and boolean flags to include/exclude axes
#macro axes(length, radii, X, Y, Z)                               
    #if (X) cylinder{ 0, < length,         0,       0>, radii texture { pigment { color rgb  < .75,-.1,-.1     > }}} #end //  X axis, red    
    #if (X) cylinder{ 0, <-length,         0,       0>, radii texture { pigment { color rgbt <   1,  0,  0, .6 > }}} #end // -X axis red translucent -adjust xmit                                                          
    #if (Y) cylinder{ 0, <      0,  length/2,       0>, radii texture { pigment { color rgb  < -.1, .5,-.1     > }}} #end //  Y axis, green    
    #if (Y) cylinder{ 0, <      0, -length/2,       0>, radii texture { pigment { color rgbt <   0, .8,  0, .6 > }}} #end //  Y axis, green translucent
    #if (Z) cylinder{ 0, <      0,         0,  length>, radii texture { pigment { color rgb  <   0,  0,  2     > }}} #end //  Z axis, Blue    
    #if (Z) cylinder{ 0, <      0,         0, -length>, radii texture { pigment { color rgbt <  .1, .1, .4, .6 > }}} #end // -Z axis blue translucent     
#end //macro axes()

#macro torusKnotBifilarCycloid(cycloidObjectA, cycloidObjectB, major, minor, poloid, toroid, polyphase, loopRadius, delta)
    union{
        #local  n  = 0;
        #while (n <= 180 * poloid - delta ) 
            #local phaz = n * toroid/poloid;            
            #if( 1 )
                object{ cycloidObjectA
                    // Move the cycloidObject away from the origin on the X axis by the minor radius.
                    translate  <minor,0,0>
                    // Toroidally rotate cycloidObject around Z axis in the XY plane.
                    rotate <0,0,phaz>
                    // Move the rotated cycloidObject to the major radius.    
                    translate <major,0,0>
                    // Rotate the object about the center Y axis of the torus.                                     
                    rotate y*n
                    // Color per the phaz rotation around the Z.
                    /*
                    texture{pigment{rgb <
                                        (.0+1*cos( radians(polyphase) + radians(360*clock) )), 
                                        -3.0,
                                        .0+1*sin( radians(polyphase) + radians(360*clock) )
                                        > }}                    
                                        */
                }
            #end                
            #local n = n + delta;
        #end
                         
        #local  n  = 180 * poloid;
        #while (n <= 360 * poloid - delta )
            #local phaz = n * toroid/poloid;            
            #if(1)
                object{ cycloidObjectB
                    // Move the spinObject away from the origin on the X axis by the minor radius.
                    translate  <minor,0,0>
                    // Rotate object around Z axis in the XY plane.
                    rotate z*phaz
                    // Move the rotated unit to the major radius.    
                    translate <major,0,0>                                     
                    // Rotate the object about the center Y axis of the torus.                                     
                    rotate y*n
                    // Color per the phaz rotation around the Z.
                    /*
                    texture{pigment{rgb <
                                        -(.0+1*sin( radians(polyphase) + radians(360*clock) )), 
                                        -3.0,
                                        .0+1*cos( radians(polyphase) + radians(360*clock) )
                                        > }}
                                        */
                }
            #end
            #local n = n + delta;
        #end           
      
        // Rotate to the polyphase position (one of three phases, e.g.)
        rotate y*polyphase    
        // Color per the phaz rotation around the Z.
                            
        
    }          
#end // macro torusKnotBifilarCycloid()

                                          
                                          
// ----------------scene------------------------


// 13/8  = 1.625
// Phi   = 1.6180339887498948482045868343656
// Difference  = 1.625 - Phi 
// Difference  = 0.00696601125010515179541316563436
 
// Torus knot parameters (loop/twist) //
#declare poloid = 13; 
#declare toroid = 8; 

// Torus dimensions.                              
#declare Phi = pow(5,.5) * .5 + .5;     // Upper case Phi = 1.618...

#declare PhiIndex   =  4;               // Set the radix of Phi for the major radius.

// Calculate orthogonal major/minor radii.
#declare radiusMajor    =             pow(Phi, PhiIndex     );
#declare radiusMinor    = radiusMajor-pow(Phi, PhiIndex - 4 ); // Four degrees of Phi smaller.
             

#declare radiusConductor = 0.094;       // 3/16" = 0.188/2" OD of 3/16" conductor.
#declare radiusConductor = 0.125/2;     // 1/8"" = 0.188/2" OD of 3/16" conductor.

//#declare conductorPlaneAngle = 14.7;    // 3:2 knot. --approximate
#declare conductorPlaneAngle = 15.365;  // 13:8 knot.  --approximate

// Delta as increment between spheres tracing torus loop in the torus knot macro. 
// The knot is a string of overlapping spheres.  Delta sets the separation.
#declare plotDelta = .03;

// Toggle parts of the scene.
#declare showBaseTorus   = 0;
#declare showTorusKnots  = 01;
#declare showConsole     = 01;

#declare showAxes   =  0;
#declare axesRadius = .01;

#declare showPhaseA = 0;
#declare showPhaseB = 0;
#declare showPhaseC = 0;

// Clock the visibility variables for phase one, two, and three.
#if(frame_number  >= 1)
    #declare showPhaseA = 1;
#end
#if(frame_number  >= 2)
    #declare showPhaseB = 1;
#end
#if(frame_number  =  3)
    #declare showPhaseC = 1;
#end

//#declare 
union{
    //plane{y,0}
    
    // Moebius bifilar torus knots.    
    #if(showTorusKnots) 
        #local cycObjA =  sphere{0,radiusConductor}; // clipped_by{plane{ z,0 rotate x*45}}};
        #local cycObjB =  sphere{0,radiusConductor}; // clipped_by{plane{-z,0 rotate x*45}}};
        #local cycObjC =  sphere{0,radiusConductor}; // clipped_by{plane{-z,0 rotate x*45}}};
        
                // Render three phases rotated 20 degrees apart //
        union{
            #if(showPhaseA) torusKnotBifilarCycloid ( cycObjA, cycObjC, radiusMajor, radiusMinor, poloid, toroid, 0,   radiusConductor, plotDelta) #end
            #if(showPhaseB) torusKnotBifilarCycloid ( cycObjA, cycObjC, radiusMajor, radiusMinor, poloid, toroid, 120, radiusConductor, plotDelta) #end
            #if(showPhaseC) torusKnotBifilarCycloid ( cycObjA, cycObjC, radiusMajor, radiusMinor, poloid, toroid, 240, radiusConductor, plotDelta) #end
            
            rotate -y*22.5 // 13:8: rotation aligns the bifilar halves with a chassis disk.
            texture{T_Copper_3C}
        }
    #end // Moebius bifilar torus knots.    
   
    #if(showBaseTorus)
        // Base torus.          
        torus{ radiusMajor,radiusMinor *.994
               texture { T_Silver_5E }
               texture { pigment{rgbt<1,1,0,.975>} } 
               texture { pigment{rgbt<1,1,0,.7>} }   
             //clipped_by{plane{z,0}}
        }
    #end

    #if(showAxes)
        axes(radiusMajor+radiusMinor*4.0, axesRadius,11,11,111)
    #end
     
    rotate -y*10
 //   rotate x*conductorPlaneAngle
    rotate z*0  // 90* for polar view, 0* for side.
}
                                      
// Print console text //
#if(showConsole)

  #declare textColor =  <1,1,.1>*0.05;
    
  //consoleObject( Object,  Position,   Spacing,     Confine, Scaling )                                
                                     
  /*
  consoleObject  ( text { ttf "crystal.ttf", concat("Fibonacci ",str(poloid,1,0), ":",str(toroid,1,0), " Orthogonal Torus Knot 3-Phase Assembly"), 0.1, <0,0>
                            scale 0.0435 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.0,.0>, true, 1 )
  */
  consoleObject  ( text { ttf "crystal.ttf", concat("Fibonacci ",str(poloid,1,0), ":",str(toroid,1,0), " Orthogonal Torus Knot"), 0.1, <0,0>
                            scale 0.0435 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.0,.0>, true, 1 )
    /*
    consoleObject  ( text { ttf "crystal.ttf", concat("Fibonacci 13:8 Torus Knot 3-Phase Assembly"), 0.1, <0,0>
                            scale 0.07 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.0,.0>, true, 1 )
    */
    consoleObject  ( text { ttf "crystal.ttf", concat("Radii to conductor centers:"), 0.1, <0,0>
                           scale 0.03 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.01,.045>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("Torus major radius: ", str(radiusMajor,0,3), 
                                                      " = Phi^(+", str(PhiIndex,0,3), ")"), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.01,.075>, true, 1 )
    
    consoleObject  ( text { ttf "crystal.ttf", concat("Torus minor radius: ", str(radiusMinor,0,3)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.01, .100>, true, 1 )
    
    consoleObject  ( text { ttf "crystal.ttf", concat("Conductor radius:   ", str(radiusConductor,1,3)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.01,.150>, true, 1 )
                                   
    consoleObject ( text { ttf "crystal.ttf", concat("Torus hole radius:  ", str((radiusMajor-radiusMinor),1,3), " = Phi^(", str(PhiIndex-4,0,3), ")"), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,1>, <.01,.125  >, true, 1 )
    
    consoleObject  ( text { ttf "crystal.ttf", concat("Torus outer tangent dia.: ", str((radiusMajor*2+radiusMinor*2+radiusConductor*2),2,3)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.05>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("Torus hole inner tangent dia.:  ", str((radiusMajor-radiusMinor-radiusConductor)*2,2,3)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.075>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("Torus tangent height:  ", str((radiusMinor+radiusConductor)*2,2,3)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.10>, true, 1 )
     consoleObject  ( text { ttf "crystal.ttf", concat("Phase A:  ", str((frame_number  >= 1),1,0)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.125>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("Phase B:  ", str((frame_number  >= 2),1,0)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.150>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("Phase C:  ", str((frame_number  = 3),1,0)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.175>, true, 1 )
                    
    // consoleObject  ( text { ttf "crystal.ttf", concat("Conductor torus plane intersect angle:  ", str((conductorPlaneAngle),2,3)), 0.1, <0,0>
    //                       scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
    //                <1,1>, <.01,.125>, true, 1 )
    
    /*
    // Bottom banner //                    
    consoleObject  ( text { ttf "crystal.ttf", concat("Cross-section disks are tangent at the center with the copper conductor through-holes."), 0.1, <0,0>
                           scale 0.025 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,0>, <.01,.0>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("39 Peripheral holes of each section disk are tie-down holes for a 3-phase set of torus knots."), 0.1, <0,0>
                           scale 0.025 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,0>, <.01,.0>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("Conductor angles approach orthogonal when the major radius of the torus is separated from the hole radius by four powers of Phi."), 0.1, <0,0>
                           scale 0.025 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <0,0>, <.01,.0>, true, 1 )
    consoleObject  ( text { ttf "crystal.ttf", concat("Camera view angle   :  ", str(( cameraViewAngle   ),2,3)), 0.1, <0,0>
                           scale 0.024 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.15>, true, 1 )
    consoleObject ( text { ttf "crystal.ttf", concat("Villarceaux circle tilt: ", str(VillarceauxRotation,3,2)), 0.2, <0,0>
                    scale 0.04 pigment {color textColor} finish {ambient 1 diffuse 0} },
                    <1,1>, <.01,.08>, true, 1 )    
    */              
#end