Polynomial Knot script

 From: bemfarmer 25 Jul 2012  (1 of 3)
 Attached is a simple script to create two Knots, as in tying a rope. The ends are not connected. The script only does the two simplist knots at present. Another 33 could be added. It is a bit hard, but it is possible to place a sweep circle perpendicular to the curve. I used a line segment tangent to the curve near the origin, to help MoI place the circle perpendicular. Michael, is there a way to "rename" the function that is called to evaluate x, y, and z point values, depending on the build type? Currently, I have the If knottype (buildtype) statement inside the for loop, a poor location. code/ if ( knottype == '3_1' ) { var pt = EvalPolyKnot3_1( t2, len, mir ); } if ( knottype == '4_1' ) { var pt = EvalPolyKnot4_1( t2, len, mir ); } I would like to place the If Else statements outside of the for loop, and have them "rename" the EvalPolyKnotxxx, in the for loop, to the correct function to use to calculate the control points of the curve. Thank you. This script came about as a result of the Belt post, and uses Michael's Lineweb and ToroidalHelix scripts "formats." http://www.m-hikari.com/ijma/ijma-password-2009/ijma-password5-8-2009/prabhakarIJMA5-8-2009-1.pdf EDITED: 8 Nov 2012 by BEMFARMER

 From: Michael Gibson 25 Jul 2012  (2 of 3)
 5279.2 In reply to 5279.1 Hi Brian, > I would like to place the If Else statements outside of the for loop, and have them "rename" the EvalPolyKnotxxx, > in the for loop, to the correct function to use to calculate the control points of the curve. There isn't really anything wrong with how you have it now, since the time required to do those if /else parts will be extremely small in comparison to any of the calls to MoI since the MoI calls work by using inter-process communication for every call. So if you're worried about it from a performance standpoint I'd say not to worry about it for that case. But the way you could make it work like you are describing would be to make a variable that holds the function to be called - in JavaScript a variable can hold a function in the same way that it can hold a piece of data. So you could do something like this (not actually tested so there might be a typo or something): code:```var func; if ( knottype == '3_1' ) func = EvalPolyKnot3_1; else if ( knottype == '4_1' ) func = EvalPolyKnot4_1; else return; for ( var i = 0; i < numpoints; ++i ) { // Call whatever function the 'func' variable currently holds. var pt = func( t2, len, mir ); ..... } ``` I think that's the kind of function "rename" thing that you're asking about - basically you put the function into a variable itself to do that. - Michael

 From: bemfarmer 25 Jul 2012  (3 of 3)
 5279.3 In reply to 5279.2 Thank you very much Michael. You make it seem so simple. Spent a few hours on google looking at anonymous functions, dynamic function renaming, eval, functions in an array... Brian