POV-Ray : Newsgroups : povray.advanced-users : Smooth, continuous Bezier splines (again) Server Time
5 Feb 2025 17:57:45 EST (-0500)
  Smooth, continuous Bezier splines (again) (Message 4 to 13 of 23)  
<<< Previous 3 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Bald Eagle
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 28 Jan 2025 14:20:00
Message: <web.67992cb396675d9f327467e125979125@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> There are still "bumps", so I think I still need to somehow account for the
> varying curvature along the splines.

So, I guess what I'm going to have to do is work out the first and second
derivatives of the Bernstein polynomials and calculate the curvature K (okay, I
already know how to do this, and have done it, and have code)

K = (x' y'' - x'' y') / (x' x' + y' y') ^ (3/2)

but then I need to figure out how to solve for sets of control point coordinates
that give me matching curvatures.

The task of fairing these curves to match "smoothly" is a conceptually
straightforward thing - hammering out the details of how to do that appears to
be a bit more mathematically involved than most would first imagine.

- BW


Post a reply to this message

From: Bald Eagle
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 28 Jan 2025 15:25:00
Message: <web.67993c5996675d9f327467e125979125@news.povray.org>
Putting this link here for reference.

https://pomax.github.io/bezierinfo/#curvature

Holy 70-page comprehensive review article! :O


Post a reply to this message

From: Bald Eagle
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 28 Jan 2025 15:55:00
Message: <web.679943ee96675d9f327467e125979125@news.povray.org>
> but then I need to figure out how to solve for sets of control point coordinates
> that give me matching curvatures.

.. . . and this must be just the thing:

https://ntrs.nasa.gov/api/citations/19900012238/downloads/19900012238.pdf


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 29 Jan 2025 10:55:00
Message: <web.679a4e6d96675d9fdd186bde89db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "ingo" <nomail@nomail> wrote:
> > The bisect of the angles in the current lines are the normals to the handles in
> > that point. The handles should be equally long to get C1/G1 (?) continuity.
> >
> > I think, without testing,
>
> Yes, excellent idea.
>...

Hi Bill

The code below shows the results of what I think Ingo suggested.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.7;

global_settings { assumed_gamma 1.0 }

#include "colors.inc"

default {
    texture {
        pigment { color White }
        finish {
            diffuse 0
            emission color White
        }
    }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro CubicBezierFn(c0, c1, c2, c3)

    function(s) {
        0
        + pow(1 - s, 3)*c0
        + 3*pow(1 - s, 2)*s*c1
        + 3*(1 - s)*pow(s, 2)*c2
        + pow(s, 3)*c3
    }

#end // macro CubicBezierFn


#macro Plot(FnX, FnY, FnZ, NoOfSegments, Radius)

    #local dS = 1/NoOfSegments;

    union {
        #local S0 = 0;
        #local p0 = <FnX(S0), FnY(S0), FnZ(S0)>;
        // sphere { p0, Radius }
        #for (I, 0, NoOfSegments - 2)
            #local S1 = S0 + dS;
            #local p1 = <FnX(S1), FnY(S1), FnZ(S1)>;
            cylinder { p0, p1, Radius }
            sphere { p1, Radius }
            #local S0 = S1;
            #local p0 = p1;
        #end // for
        #local S1 = S0 + dS;
        #local p1 = <FnX(S1), FnY(S1), FnZ(S1)>;
        cylinder { p0, p1, Radius }
        // sphere { p1, Radius }
    }

#end // macro Plot

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare Debug = false;


#declare NoOfPoints = 9;
#declare Points =
    array[NoOfPoints] {
        <-0.297/2, -1.000, 0.000>,
        <-0.203/2, -0.500, 0.000>,
        <-0.115/2, -0.250, 0.000>,
        <-0.069/2, -0.125, 0.000>,
        < 0.000/2,  0.000, 0.000>
        <+0.069/2, -0.125, 0.000>,
        <+0.115/2, -0.250, 0.000>,
        <+0.203/2, -0.500, 0.000>,
        <+0.297/2, -1.000, 0.000>,
    }
;

#declare R = 0.006;

#if (true)
    union {
        #for (I, 0, NoOfPoints - 1)
            sphere { Points[I], R }
        #end // for
        pigment { color White }
    }
#end // if


#declare NoOfOrthogonalVectors = NoOfPoints - 1;
#declare OrthogonalVectors = array[NoOfOrthogonalVectors];
#for (I, 0, NoOfOrthogonalVectors - 1)
    #declare OrthogonalVectors[I] = vnormalize(vcross(Points[I+1] - Points[I],
z));
#end // for

#if (Debug)
    union {
        #for (I, 0, NoOfOrthogonalVectors - 1)
            cylinder {
                0*z, OrthogonalVectors[I], R/4
                translate (Points[I] + Points[I+1])/2
            }
        #end // for
        pigment { color Red }
    }
#end // if


#declare NoOfBisectingVectors = NoOfPoints;
#declare BisectingVectors = array[NoOfBisectingVectors];
#declare BisectingVectors[0] = OrthogonalVectors[0];
#for (I, 1, NoOfBisectingVectors - 2)
    #declare BisectingVectors[I] = vnormalize(OrthogonalVectors[I-1] +
OrthogonalVectors[I]);
#end // for
#declare BisectingVectors[NoOfBisectingVectors-1] =
OrthogonalVectors[NoOfOrthogonalVectors-1];

#if (Debug)
    union {
        #for (I, 0, NoOfBisectingVectors - 1)
            cylinder {
                0*z, BisectingVectors[I], R/4
                translate Points[I]
            }
        #end // for
        pigment { color Magenta }
    }
#end // if


#declare NoOfTangentVectors = NoOfBisectingVectors;
#declare TangentLengths =
    array[NoOfTangentVectors] {
        0.10,
        0.10,
        0.08,
        0.04,
        0.01,
        0.04,
        0.08,
        0.10,
        0.10
    }
;
#declare TangentVectors = array[NoOfTangentVectors];
#for (I, 0, NoOfTangentVectors - 1)
    #declare TangentVectors[I] = TangentLengths[I]*vcross(+z,
BisectingVectors[I]);
#end // for

#if (Debug)
    union {
        #for (I, 0, NoOfTangentVectors - 1)
            cylinder {
                0*z, +TangentVectors[I], R/4
                translate Points[I]
            }
            cylinder {
                0*z, -TangentVectors[I], R/4
                translate Points[I]
            }
        #end // for
        pigment { color Blue }
    }
#end // if


#declare NoOfSegments = 16;
#for (I, 0, NoOfPoints - 2)
    #declare pA = Points[I  ];
    #declare pB = Points[I  ] + TangentVectors[I  ];
    #declare pC = Points[I+1] - TangentVectors[I+1];
    #declare pD = Points[I+1];
    #if (Debug)
        union {
            // sphere { pA, R }
            sphere { pB, R }
            sphere { pC, R }
            // sphere { pD, R }
            pigment { color Blue }
        }
    #end // if
    object {
        Plot(
            CubicBezierFn(pA.x, pB.x, pC.x, pD.x),
            CubicBezierFn(pA.y, pB.y, pC.y, pD.y),
            CubicBezierFn(pA.z, pB.z, pC.z, pD.z),
            NoOfSegments,
            R/4
        )
        pigment { color Black }
        translate -1.0*z
    }
#end // for

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color Gray40 }

#declare AR = image_width/image_height;

camera {
    orthographic
    location < 0.0, -0.5, -2.0>
    right AR*x
    up y
    direction z
    angle 30
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

From: William F Pokorny
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 29 Jan 2025 12:34:11
Message: <679a6693$1@news.povray.org>
On 1/29/25 10:51, Tor Olav Kristensen wrote:
> #macro CubicBezierFn(c0, c1, c2, c3)
> 
>      function(s) {
>          0
>          + pow(1 - s, 3)*c0
>          + 3*pow(1 - s, 2)*s*c1
>          + 3*(1 - s)*pow(s, 2)*c2
>          + pow(s, 3)*c3
>      }
> 
> #end // macro CubicBezierFn

Perhaps time to add an inbuilt f_bezier_cubic() to yuqk too. :-)

Bill P.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 29 Jan 2025 13:30:00
Message: <web.679a730696675d9fdd186bde89db30a9@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
> On 1/29/25 10:51, Tor Olav Kristensen wrote:
> > #macro CubicBezierFn(c0, c1, c2, c3)
> >
> >      function(s) {
> >          0
> >          + pow(1 - s, 3)*c0
> >          + 3*pow(1 - s, 2)*s*c1
> >          + 3*(1 - s)*pow(s, 2)*c2
> >          + pow(s, 3)*c3
> >      }
> >
> > #end // macro CubicBezierFn
>
> Perhaps time to add an inbuilt f_bezier_cubic() to yuqk too. :-)

Yes, that would be nice.

Then comes the question if adding f_bezier_quadratic() and f_bezier_quartic()
also is a good idea.

And then if the various derivative functions of them should be added...

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Bald Eagle
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 29 Jan 2025 14:20:00
Message: <web.679a7ef296675d9f327467e125979125@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> William F Pokorny <ano### [at] anonymousorg> wrote:

> > Perhaps time to add an inbuilt f_bezier_cubic() to yuqk too. :-)
>
> Yes, that would be nice.
>
> Then comes the question if adding f_bezier_quadratic() and f_bezier_quartic()
> also is a good idea.
>
> And then if the various derivative functions of them should be added...

I thought there was already some kind of Bezier spline function - but maybe not
as a proper function.  We have that spline in prism {}.  Unless we consider
user-defined spline functions "good enough".

Might it not be "easier", more useful, and more general to have a single
Bezier/Bernstein function that takes the number of control points as an
argument, and can just assemble the spline on the fly? Then you wouldn't need
multiple functions.

And aren't the derivatives just other Bezier splines?

I'm just thinking that if it was done that way, people could really begin to
harness the power of these splines without having to ascend the steep learning
curve.

Also having a feature where the user could just switch over to a linear spline
would allow looping through the control points - perhaps to draw out the control
points and polygon - without having to write another whole block of code to do
so.

Degree elevation and reduction would be super sweet to have as well.

And, if you want, I can provide the curvature functions - which are useful for
designing function-driven textures, examining how splines fit together, etc.

Big rabbit hole to go down, but IMHO, in 2025, a computer graphics program
really ought to have an entire in-built Bezier spline library.

- BW


Post a reply to this message

From: William F Pokorny
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 29 Jan 2025 15:02:39
Message: <679a895f$1@news.povray.org>
On 1/29/25 13:27, Tor Olav Kristensen wrote:
>> Perhaps time to add an inbuilt f_bezier_cubic() to yuqk too. 🙂
> Yes, that would be nice.
> 
> Then comes the question if adding f_bezier_quadratic() and f_bezier_quartic()
> also is a good idea.
> 
> And then if the various derivative functions of them should be added...

I've grabbed code over time for some 2D functions I planned to call 
f_bezier_2d_quartic() and f_bezier_2d_quintic().

Do you have - or know of - 3D code for either of these?

Or for a 3D quadratic?  I might have the quadratic 3D form in my notes 
notes somewhere or in my TCL wrapper script (where I'd coded up some 
simpler spline by segment types maybe 15 years ago). I wonder if 
quadratic that useful excepting having better performance?

FYI. As yuqk inbuilt functions the convenient versions (packed vectors) 
for 3D forms would be limited to a -10 to +10 box and single float 
accuracy rather than double for the any 2D forms.

As for the derivative forms, if you have code in hand, maybe we do a few 
  near term? I don't have anything ready to go.

The question too is whether some of this 'spline stuff' better fits in 
spline{} like SDL feature - one supporting the Bezier segment control 
point forms. We can describe many segment curves, function wrap, but 
what we can do dynamically from the render time VM is limited.

Aside: Jerome coded up a bunch of spline extensions in his hgpovray38 
fork (which 'maybe' came from megapov?). I don't recall any additional 
Bezier support, but my memory is not great these days.

Bill P.


Post a reply to this message

From: Bald Eagle
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 29 Jan 2025 15:30:00
Message: <web.679a8f9996675d9f327467e125979125@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:

> I've grabbed code over time for some 2D functions I planned to call
> f_bezier_2d_quartic() and f_bezier_2d_quintic().
>
> Do you have - or know of - 3D code for either of these?
>
> Or for a 3D quadratic?

Maybe I'm misunderstanding, but:
They're not dimensional - they're parametric.
Take any N-D point and the spline just interpolates ALL of the dimensions with
the same equations.
Right?


Post a reply to this message

From: Bald Eagle
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 29 Jan 2025 15:50:00
Message: <web.679a939896675d9f327467e125979125@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

> The code below shows the results of what I think Ingo suggested.

Thank you.  I thought this would grab your attention - however I was hoping to
get some free time to do something with it before you submitted the solution!
:D
Too late.  You win.

I'll take a look when I get home in an hour.


Post a reply to this message

<<< Previous 3 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.