• Torus knot OpenSCAD code‚Äč

    09/30/2021 at 11:30 0 comments

    //  File: torus_knot-XYZ3.scad                             

    //  Author: DonEMitchell, Westcliffe, CO
    //  Copyright DonEMitchell, Feb. 9, 2019

    //  Description: A parameterized torus knot module using calculated XYZ coordinates.
    //  Purpose: Generate a hulled-sequence (skinned) of spheres arranged along the path of a torus knot wound on a torus.  
    //                                                               
    //    Module parameters: (R)majorRadius, (r)minorRadius,
    //      knotRevolutions(p), knotTwists(q)
    //      stepDegrees, loopDia
    //
    //  Caveat:  The torus knot arc hulled-segments are looped from zero to 360, overlapping zero and 360 to close of the torus knot hull.

    /// Calculate constant Phi and define pi:
    Phi = pow(5,.5)*.5+.5;   // Φ = ϕ = 1.61803399 dot dot dot.
    pi = 3.14159265;         // Π  = Π = 3.14159265 dot dot dot.

       /////////////////////////////////////////////////////////
      ///  Set module variables, torus and torus knot       ///
     ///  parameters to create a golden orthogonal knot**  ///
    /////////////////////////////////////////////////////////

    /// **A golden orthogonal knot has inner loops of the torus knot 
    ///   crossing the torus plane through the torus hole at a 90 degree
    ///   separation (orthogonal) from the angle of the outer loops 
    ///   crossing the torus plane.  The torus knot ratio (p,q) is any two 
    ///   neighboring numbers on the Fibonacci sequence, so the torus 
    ///   knot ratio is a Fibonacci approximation of the golden ratio.

    ///  Set p:q parameters as an adjacent pair of numbers
    ///  in the Fibonacci sequence:
    ///  p Divided by q approximates the golden ratio when
    //      q = F(n) and
    //      p = F(n+4)
    // where F(n) equals the nth Fibonnacci number in the Fibonacci sequence.

    p = 13; // Helical twists around the torus tube forming the torus surface.
    q =  8; // Axial rotations (Z) radially sweeping in the X,Y plane.

    ///  Set the major radius and 'hole' radius of the torus
    ///  to powers of the golden ratio. 'Hole' radius = R - r.

    R =     pow(Phi,4);    // Torus major radius.
    r = R - pow(Phi,0);    // Torus minor radius.
    // Fudge r a scooch to adjust torus to proper bury-depth of the knot into the torus.

    /// Torus knot appearance parameters:
    loopDia     = 2;       // Fatness of the torus knot loop. 
    stepDegree  = 1;       // for-loop incrementing variable.
    fnTorus     = 39;
    fnTorusKnot = 4;    

    phaseCount = 3;
    // Default the module to a golden orthogonal torus knot.
    module torusKnotXYZ(
            p           = 3, // Default parameter values 
            q           = 2,
            R           = 2.61803,
            r           = 2.236068,
            showTorus   = true,
            stepDegree  = 1/2,
            loopDia     = .125,
            fnTorus     = 39,// Face number of torus.
            fnTorusKnot = 4, // Face number for a square loop cross section.
            phaseCount  = 1
            ){

        phaseSeparation = 360/phaseCount;

        /// R:r Is...

    Read more »