# Add Mesh Extra Objects - Torus Knots

Posted this over at StackExchange. Too unclear. Too many links.

So, I’ll post it here instead. Still good, useful info. Just doesn’t require a Best Answer.

How do I convert this to working code & find similar formulas?

Add Mesh Extra Objects - Torus Knots has seen very little love these days. I’m trying to play around with it, but, most formulas I see are greek to me or don’t seem to readily translate.

Either under Add Mesh Extra Objects or perhaps as nodes (Sverchok or Animation Nodes - maybe).

Also looking for comparable / workable Torus Knot formulas.

These come outside of what’s currently available in Blender, so, I thought it might be interesting if I could find a way to translate them for Blender.

This is the closest I’ve found:

from here:

Decorative Knot Patterns

What I’ve tried based on input formats in the Add Mesh Extra Objects script ( Example 12 ( c ) ) in the image :

``````def k5(t):
x = cos(3 * t) * (1 - 0.525 * (cos(2 * t) - cos(t) + 0.6 * cos(7 * t)))
y = sin(3 * t) * (1 - 0.525 * (cos(2 * t) - cos(t) + 0.6 * cos(7 * t)))
z = 0.2 * sin(5 * t) - sin(2 * t)
return Vector([x, y, z]) * 0.2
``````

[Note: the funny looking “0”'s are mathematical for “Theta” in code represented by “t” (as in tom).

Tweaking it, I got this, (as is)

and this: (using 2 instead of 0.2)

``````    return Vector([x, y, z]) * 2
``````

Neither close or even pretty.

So, moving on, I found this link:

Decorative Knotting Using Trigonometric Parametrizations

With some very useful code. The code works verbatim, but, some results, as shown below require some tweaking:

Haven’t looked into using nodes yet. If anyone has any insights in that regard, or how to fix the problematic or currently not working code, feel free to share them.

Attached below is the blend file with the code. The updated script, should be added where you keep the add_mesh_extra_objects folder on your system is in the Blender file. Save it as: add_mesh_torusknot.py. You might want to make a backup of the original before overwriting it. (On my MacBook it’s in the Contents / Resources / Addons folder of the Executable Blender file in the Applications Folder)

There are many examples that extend well beyond the 3 provided by Blender. The original author is no mathematician. Neither am I, but, those of you who are (or are not) might appreciate the possibilities.

Hope you find it useful.

(I’ve also added an extra knot - not in the code - Fig 8 - from Kit Wallace - converted from Openscad, saved to OFF format, converted to OBJ using Meshlab and cleaned up in Blender:

I set the object to Shade Flat to show the edges, selected one Edge loop, inverted the selection, deleted the other edges and converted the result to a curve.

Then I added a circle, 8 sides to match the original. Converted the circle to a curve, used it as an object thickener on the knot.

Saved it to a mesh. And used this handy trick to simplify the result:

Super fast geometry reduction using Checker Deselect in Blender

Kit Wallace Openscad Site for Torus Knots - Fig 8 Knot

Enjoy.

2 Likes