POV-Ray : Newsgroups : povray.advanced-users : Smooth, continuous Bezier splines (again) Server Time
5 Feb 2025 15:14:27 EST (-0500)
  Smooth, continuous Bezier splines (again) (Message 1 to 10 of 23)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Bald Eagle
Subject: Smooth, continuous Bezier splines (again)
Date: 27 Jan 2025 14:55:00
Message: <web.6797e39ce9acc1774cc51b5c25979125@news.povray.org>
I've got a diagram of where measured points should be along a CURVE that
describes the profile of a solid edge.

You can see from the diagram, that a linear connection of the points would give
me a shape where the measured dimension points would be at the vertices of
concave angles, and so the appropriately shaped object {} would touch the lines
rather than the dimension points.

What I'd like to do is use those dimension points as the endpoints of Bezier
splines, such that the resulting curve was smooth and continuous.

I feel like, after all of the Bezier spline research that I've done, that I
really _ought_ to be able to just do this off the top of my head; however,
although I can make a continuous spline that's "smooth" and intersects the
dimension points, I don't get an "adequately" smooth curve - it has "wiggles".

This leads me to believe that either need to degree elevate the spline in order
to match the _curvature_ of the segments

OR

I need to degree reduce the cubic splines to quadratic splines so that I only
have a single intermediate control point.

I tried to quickly test that out by just making the 2 internal control points
the same, however since the control points to either side of the endpoints need
to be colinear with the control point, and preferably offset by a vector of the
same magnitude, that's a problem when the spline segments are different lengths.

So I'm leaning toward degree elevation.
But that seems like it would open things up to even MORE wiggle, and I have no
idea at the moment how to calculate the position of that extra control point.

I'm just stuck trying to figure out / remember how to calculate the positions of
the internal control points.

- BE


Post a reply to this message


Attachments:
Download '8468.png' (29 KB)

Preview of image '8468.png'
8468.png


 

From: ingo
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 28 Jan 2025 01:25:00
Message: <web.6798782996675d9f17bac71e8ffb8ce3@news.povray.org>
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,

ingo


Post a reply to this message

From: Bald Eagle
Subject: Re: Smooth, continuous Bezier splines (again)
Date: 28 Jan 2025 13:45:00
Message: <web.679924fb96675d9f327467e125979125@news.povray.org>
"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.

I was futzing around with something along those lines yesterday, but I'm stuck
doing it in M$ Office 365 Copilot web version - which is painful enough - but I
was working on it piecemeal, so I only had so much time in one stretch to focus.

At present, I take 3 control points, bisect the angle, find the perpendicular
slope (negative reciprocal), use the equation of that line to sub in 1/3 of the
shorter vector, and solve for the control point y-values on either side of the
endpoint.

I have the Bezier splines charted using the Bernstein polynomials, and
concatenated together using "helper cells".

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


Post a reply to this message


Attachments:
Download 'screenshot 2025-01-28 133147.png' (129 KB)

Preview of image 'screenshot 2025-01-28 133147.png'
screenshot 2025-01-28 133147.png


 

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

Goto Latest 10 Messages Next 10 Messages >>>

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