Trefoil: For the math gurus

I wrote this based on math Here which was the easy part…

The code runs fine, and spits out this geometry

Id like to add a command line option to control the total outer diameter of the trefoil created… but as math guru is not one of the hats I wear I’m at a loss where to inject the factor that fixes total outter diameter in that formula above… anyone care to take a punt?

Mobile punt: multiply x and y by a factor = to desired outer diameter?

gave that a go, using same factor, it does increase and decrease as expected, but I cant figure out the math so the user can input "I want a trefoil exactly 77.8mm diameter for example.

I took a poke at changing the “2” value in that formula… I waited about ten minutes and got a fantastic bowl of spaghetti back… (thinking of creating a spaghetti command actually)

I think the answer here will be to create a circle and flow this inside of it.

whoops deleted code from main post.

 public class Trefoil : Command
        public override string EnglishName
        { get { return "Trefoil"; } }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            Point3dList points = new Point3dList((int)(2 * Math.PI));
            for (double t = 0; t <= (Math.PI * 2); t += 0.1)
                Point3d P = new Point3d(
                (Math.Sin(t) + 2 * Math.Sin(2 * t)), //X
                (Math.Cos(t) - 2 * Math.Cos(2 * t)), //Y
                (-Math.Sin(3 * t)));                 //Z
            NurbsCurve nc = NurbsCurve.Create(true, 3, points);
            return Result.Success;
1 Like

Mobile punt #2: I would do everything in one unit, and then apply the factor.

Hi Christopher,

your major radius in the example above is 3. To create the knot with a desired major radius, divide the xyz point components with 3.0 then multiply with your desired value.

Ps. Your stepsize (0.1) is not very fine, so you will measure probably a major radius slightly below 3.0. btw. using a constant stepsize is not as good as dividing the range between 0 and 2 * Math.PI into equal steps. You see that near the curve seam if you turn on the curvature graph after closing the open curve.


Your formula for a trefoil is a bit odd. A trefoil is an example of a torus knot. Here’s a general formula for any torus knot:

V=R*(sin(t), cos(t), 0)

The points of K will lie on a p,q torus knot, as long as you let t vary from 0 to 2piq. The trefoil is a 2,3 torus knot. The parameter R in the above is the distance form the origin to the center of the torus on which the knot sits. The parameter r is the width of the cross section of the torus, so that R+r will be the total diameter.

sweet, ill have a poke at that tonight. I think I got my head around sizing these blasted awkward shapes though.