POV-Ray : Newsgroups : povray.binaries.scene-files : Making functions for natural cubic splines : Re: Making functions for natural cubic splines Server Time
28 Apr 2024 03:27:44 EDT (-0400)
  Re: Making functions for natural cubic splines  
From: clipka
Date: 13 Oct 2014 01:18:23
Message: <543b609f$1@news.povray.org>
Am 13.10.2014 05:24, schrieb Nevado:

> I agree about the language, and I first believed this was an impossible task,
> but I did find a way to draw PointWriter shapes with cubic splines in JustBasic.
> (Luckily, two dimensions are enough for my purposes.) My method takes four user
> points A, B, C and D, solves the cubic curve that connects them, draws the
> middle segment from point B to C, then moves on to solve B, C, D and E, draws
> the segment from C to D and so on. This produces nicely flowing curves. But I
> keep running into problems when the curve doubles back on itself, needing two
> y-values for the same x-value. The problem arises because the points are
> connected in order of increasing x, not in the order the points are clicked.
> So when I want this:
>
>         D
>           *
>            *
>             C
>           *
>         *
>       B
>     *
> A
>
> I get this:
>
>
>         D
>        *  *
>        *   *
>       *     C
>       *
>       *
>       B
>     *
> A

Here's some misconception about splines: Each segment is /not/ defined 
by a simple function mapping x coordinates to y coordinates like this:

     y = f(x) = a x^2 + b x + c

Instead, a spline segment in 2D space is defined by a /pair/ of 
functions, each mapping some /third/ value (often denoted as "t" and 
typically ranging from 0 to 1 within each segment) to one of the 
coordinates, e.g.:

     x = f_x(t) = a_x t^2 + b_x t + c_x
     y = f_y(t) = a_y t^2 + b_y t + c_y

or, using vector notation:

     (x,y) = f(t) = (a_x,a_y) t^2 + (b_x,b_y) t + (c_x,c_y)

To understand what the "t" parameter means, think of a cubic spline as 
the trajectory of an object that undergoes some constant acceleration 
within each segment; then, the coefficient

     (c_x,c_y)

is equal to the position of the object at the beginning of the segment,

     (b_x,b_y)

is equal to the speed of the object at the beginning of the segment,

     (a_x,a_y)

is equal to the acceleration of the object in this spline segment, while

     t

is the time since the beginning of the segment.


Post a reply to this message

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