POV-Ray : Newsgroups : povray.advanced-users : quadratic & cubic splines : Re: quadratic & cubic splines Server Time
30 Jul 2024 08:19:15 EDT (-0400)
  Re: quadratic & cubic splines  
From: Leroy Whetstone
Date: 23 Dec 1999 13:14:23
Message: <386281BC.4536C7D7@janics.com>
Well! I finally done it. I asked a question that no one was willing or able
to  answer.
Maybe I just asked in the wrong group.
But here's a quick look at what I've found:

// bezier spline formula  ---------------------
 I found this at http://www.moshplant.com/direct-or/bezier/

(ControlX0,ControlY0) the first control point
(PointX0,PointY0)     the first point
(ControlX1,ControlY1)  the second control point
(PointX1,PointY1)      the second point

Cx = 3 * (ControlX0 - PointX0):  Cy = 3 * (ControlY0 - PointY0)
Bx = 3 * (ControlX1 - ControlX0) - Cx: By = 3 * (ControlY1 - ControlY0) - Cy

Ax = PointX1 - PointX0 - Cx - Bx:    Ay = PointY1 - PointY0 - Cy - By

for t=0 to 1 step .01
Xp = Ax * t ^ 3 + Bx * t^2 + Cx*t + PointX0  ' X location
Yp = Ay * t ^ 3 + By * t^2 + Cx*t + PointY0 ' Y location
plot(Xp,Yp)
next

// Cubic spline formula   ---------------------
 I used the basic bezier formula with second control point at the start
 equal to the slope between the first point and the third point divid by 3
 add to the second point.

// quadric spline formula ---------------------
 I just got lost in the web of quadratic stuff on the net and never could
 find a formula for the spline. So I played with what I knew about bezier
 and wrote this. It seems to work alright.

(ControlX0,ControlY0) the control point
(PointX0,PointY0)      the first point
(PointX1,PointY1)      the second point

Bx = 2 * (ControlX0 - PointX0): By = 2 * (ControlY0 - PointY0)
Ax = PointX1 - PointX0 - Bx: Ay = PointY1 - PointY0 - By

for t=0 to 1 step .01
Xp = Ax * t ^ 2 + Bx * t + PointX0  ' X funtion
Yp = Ay * t ^ 2 + By * t + PointY0 ' Y funtion
plot(Xp,Yp)
next

When it comes time to do the next curve, the control point becomes
 the next point plus the slope between the point before and the point after
  divide by 3.
----------------------------------------------------------
I hope this can help someone else.


Post a reply to this message


Attachments:
Download 'us-ascii' (3 KB)

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