Created by: portnov
From #3306 (closed).
To "rotate matrix according to curve's tangent", we have the following approaches:
a) historically (in Sverchok) the first: use Householder, Tracking or Rotation Difference algorithm. These algorithms take two vectors: initial tangent direction and tangent direction you want, and return a rotation matrix that converts the source tangent direction to the target. Note: these algorithms do not know at all what the "curve" is. They depend on tangent direction only.
b) Frenet and "zero-twist" algorithms. Frenet algorithm takes Frenet matrix of the curve, made from tangent direction, normal and binormal directions of the curve. "Zero-twist" is similar, it takes Frenet matrices first, and then it "substracts" rotation around the tangent, which is calculated by integrating curve torsion. These algorithms are not "curve-agnostic", they are based on differential geometry, so for "good" curves they give better results. "Good" means curve with non-zero curvature, i.e. curve which has non-zero second derivative in all points. If the curve has points with zero curvature, or, even worse, it has straight segments, then everything is suddenly very bad.
c) New algorithm. First, let's split curve in N pieces and calculate tangent vectors at these points ("knots"). Then we take curve's normal vector at curve's starting point (let's assume that at least at this point the curve has non-zero curvature). Then we iterate through all knots. At each knot, we build a plane through the knot point, orthogonal to curve's tangent vector at this knot point; and we project normal vector from previous point to this plane. So we have N normal vectors. Then for any value of T in curve's domain, we can calculate normal vector by interpolating normals between knot points somehow. In the following script, quaternions linear interpolation is used.
For compassion, "Tracking" algorithm, which for this particular curve gives the best result among all implemented algorithms:
Note the twisting at the left side.
Another example:
Preflight checklist
Put an x letter in each brackets when you're done this item:
-
Code changes complete. -
Code documentation complete. -
Documentation for users complete (or not required, if user never sees these changes). -
Manual testing done. -
Unit-tests implemented. -
Ready for merge.