December 2014

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      










« Minor update to the DGN Purge command | Main | A new version of DesignScript on Autodesk Labs »

July 17, 2013

More knots in Tinkercad using JavaScript

After working out how generally to use Brandon Cole’s Shape Script code to display mathematical shapes in Tinkercad, I carried on looking for some interesting functions to “plot”. I ended up finding definitions for two Cinquefoil knots, specifically the (2,5) and the (5,2) variations (I also tried the (5,1), but that ended up looking just like the (5,2)). This “page that once was” helped a great deal with the underlying formulae, as of course did the online derivative calculator (Brandon tells me he personally used Wolfram Alpha to calculate his derivatives, a site I’ve blogged about in the past).

Here are the relevant lines of JavaScript for each of the knots…

Cinquefoil 2,5:

    // Equation... 

 

    pt =

      new XYZ(

        Math.cos(2 * t) * (5 + 2 * Math.cos(5 * t)),

        Math.sin(2 * t) * (5 + 2 * Math.cos(5 * t)),

        2 * Math.sin(5 * t));

 

    // Equation Derivative...

 

    pt_d =

      new XYZ(

        -10 * Math.cos(2 * t) * Math.sin(5 * t) -

          2 * Math.sin(2 * t) * (2 * Math.cos(5 * t) + 2),

        2 * Math.cos(2 * t) * (2 * Math.cos(5 * t) + 5) -

          10 * Math.sin(2 * t) * Math.sin(5 * t),

        10 * Math.cos(5 * t));

Cinquefoil 5,1:

    // Equation... 

 

    pt =

      new XYZ(

        (Math.cos(t) + 2) * Math.cos(5 * t),

        (Math.cos(t) + 2) * Math.sin(5 * t),

        -Math.sin(t));

 

    // Equation Derivative...

 

    pt_d =

      new XYZ(

        -5 * (Math.cos(t) + 2) * Math.sin(5 * t) -

          Math.sin(t) * Math.cos(5 * t),

        5 * (Math.cos(t) + 2) * Math.cos(5 * t) -

          Math.sin(t) * Math.sin(5 * t),

        -Math.cos(t));

Cinquefoil 5,2:

    // Equation... 

 

    pt =

      new XYZ(

        (Math.cos(2 * t) + 2) * Math.cos(5 * t),

        (Math.cos(2 * t) + 2) * Math.sin(5 * t),

        -Math.sin(2 * t));

 

    // Equation Derivative...

 

    pt_d =

      new XYZ(

        -5 * (Math.cos(2 * t) + 2) * Math.sin(5 * t) -

          2 * Math.sin(2 * t) * Math.cos(5 * t),

        5 * (Math.cos(2 * t) + 2) * Math.cos(5 * t) -

          2 * Math.sin(2 * t) * Math.sin(5 * t),

        -2 * Math.cos(2 * t));

 

Here are the resulting objects inside the public model with the shared Shape Scripts:

Knots, knots, knots

blog comments powered by Disqus

Feed/Share

10 Random Posts