- // loop is shape in 3d with (0,0) at path[i], shape's
- // z axis in the direction of shapenormals[i], and
- // shape's x axis in the direction of pathnormals[i].
- // We tack [1,0,0] onto the end as a hack to see where
- // it ends up after rotation. This is removed later.
- var loop = shape.concat([[1,0,0]]);
+ var shapenormali = shapenormal_fun(i, path[i]);
+ var pathnormali = pathnormal_fun(i, path[i], shapenormali);
+
+ // Fix pathnormali to be perfectly perpendicular to
+ // shapenormali. pathnormali must be perpendicular to
+ // shapenormali or the second rotation will take loop
+ // back out of the shapenormali plane that the first
+ // rotation so carefully placed it in. But, letting
+ // callers be sloppy with the pathnormals can greatly
+ // simplify generating them -- so much so that you can
+ // often just pass a constant to use the same value
+ // along the whole path.
+ pathnormali = this.project_to_orthogonal(shapenormali, pathnormali);
+
+ var shapei = shape_fun(i, path[i], shapenormali, pathnormali);
+
+ // loop is shapei in 3d with (0,0) at path[i], shape's
+ // z axis in the direction of shapenormali, and shape's
+ // x axis in the direction of pathnormali. We tack
+ // [1,0,0] onto the end as a hack to see where it ends
+ // up after the first rotation. This is removed later.
+ var loop = shapei.concat([[1,0,0]]);