POV-Ray : Newsgroups : povray.off-topic : Interpolation of 2D points : Re: Interpolation of 2D points Server Time
28 Jul 2024 10:23:34 EDT (-0400)
  Re: Interpolation of 2D points  
From: scott
Date: 10 Sep 2014 12:20:41
Message: <54107a59$1@news.povray.org>
> Given an array of {t, Point} where t is a floating point number, between
> 0 to 1, and Point is a point in the 2D plane. (The array can be sorted
> by ascending t.)
>
> Now I want a formula f(t) that returns a "smooth path" going through all
> these points.

Unfortunately there is no simple formula/algorithm and you'll need to do 
a bit of maths and geometry if you're coding it all yourself.

Start by splitting the curve up into segments between each point and 
have a separate f(t) for each segment. A cubic bezier will likely be 
your best bet and it is guaranteed to actually go through all points and 
you can control the gradient (in space and time) at the start and end of 
each segment to match with the neighbours.

Here is a good demo to get the feel of what the control points do:

http://blogs.sitepointstatic.com/examples/tech/canvas-curves/bezier-curve.html

Wikipedia has the formulas you need, use the 2nd one from this section:

http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves

P0 and P3 are your start and end points in each section, P1 and P2 are 
"control points" that control the shape of the curve. Looking at the 
equation further down for B'(t) you can figure out that for the adjacent 
segments to match in gradient you need P1-P0 of one segment to equal 
P3-P2 of the next section.


Post a reply to this message

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