POV-Ray : Newsgroups : povray.advanced-users : Length of spline... : Re: Length of spline... Server Time
30 Jul 2024 02:16:18 EDT (-0400)
  Re: Length of spline...  
From: Chris Colefax
Date: 22 Oct 2000 23:26:29
Message: <39f3afe5@news.povray.org>
Tony[B] <ben### [at] panamac-comnet> wrote:
> How can I get an exact/closely approximated measure of the distance
traveled
> along a spline and the total length of it? I am using a cubic_spline in
> MegaPOV.

Due to the maths involved, there is no known way to calculate the exact
length of a cubic spline.  The best method is usually to sum the linear
distances between a number of steps along the spline - obviously, the more
steps, the more accurate the result (at the cost of speed).  In MegaPOV you
should be able to do this quite simply using a while loop (the following
presumes your spline clock ranges from 0 to 1):

   #declare MySpline = spline {cubic_spline ..... }
   #declare Length = 0;

   #declare C = 0; #while (C <= 100)
      #declare P1 = MySpline(C/100);
      #if (C > 0) #declare Length = Length + vlength(P1 - P0); #end
      #declare P0 = P1;
   #declare C = C + 1; #end

Also, a very rough approximation can be calculated if know the bezier hull
points of the spline.  My own Spline Macro file uses a combination of both
methods, so you can return the total length of a spline, return a point at a
specified distance along a spline, or even specify a list of points and a
length, and have the macro tension the spline through the points to fit the
desired length.


Post a reply to this message

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