Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c# - How to create bezier curves for an arc with different start and end tangent slopes

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:

enter image description here

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:

enter image description here

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: enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have some segment of 3d curve with known tangents at endpoints and want to build Bezier approximation.

Inner control points of Bezier curve will lie on vectors collinear with tangent vectors. But you need to know their length.

Approximation approach for circle arc chooses such length of these vectors to provide middle Bezier point coinciding with middle point of arc. You can apply the same method here. Write

P1 = P0 + T0 * L
P2 = P3 - T3 * L

substitute in Bezier equation with t=1/2, P = middle of the curve and find unknown L. Make this for all three components and get some average providing rather good error (perhaps some optimization is possible).

If curve is highly unsymmetric - someone may try to use different lengths for both tangents.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...