I've been stuck on this for a week now i can't seem to solve it.
I have an arc which i can convert to a series of bezier curves quite easily when the arc is flat:
But i am struggling to work out how to find the bezier curves when the arc is a helix and the end tangents have different slopes.
This is as far as i have gotten so far:
As you can see each bezier curve has control points that are not on the right plane, and the start and end tangent (the red vectors in the second image) of the full arc is not factored in as i couldn't work out how to do it.
To find the flat version of the bezier slices from arcs i have this piece of code which certainly works fine for a flat arc:
// from https://pomax.github.io/bezierinfo/#circles_cubic
public CubicBezier ConvertArc(Vector3 origin, float radius, Vector3 from, Vector3 to, float angle)
{
var c = Math.Tan(angle * Mathf.Deg2Rad / 4f) * 4 / 3f * radius;
var c1 = from + (from - origin).Perp().normalized * c;
var c2 = to - (to - origin).Perp().normalized * c;
return new CubicBezier(from, c1, c2, to);
}
This is my current code to create each bezier cut:
//cut the arc in to bezier curves up to 90 degrees max
float cuts = _arc.totalAngle / 90f;
for (int i = 0; i < cuts; i++)
{
float t = i / cuts;
float t2 = (i + 1) / cuts;
Arc slice = new Arc(_arc,_arc.Point(t),_arc.Point(t2));
//this function below is the issue, it needs start and end tangent for the slice,
//but i also don't know how to find the tangents at each slice for the whole arc
//relating the start and end tangents of the entire arc
//see above snippet for function code
var cb = ConvertArc(slice.origin, slice.radius, slice.a, slice.b, slice.totalAngle);
cb.DebugDraw(Color.yellow);
}
Hope some one can help explain the logic to solve how to find the control points correctly to match the tangents, wasted a week already with little progress.
This is written in C# but i don't think the language matters, math is math no matter the language.
A visual (albeit poor drawing) of how i want the result to respect the end tangent slopes:
See Question&Answers more detail:
os