POV-Ray : Newsgroups : povray.advanced-users : Optimized curves : Re: Optimized curves Server Time
30 Jul 2024 06:18:24 EDT (-0400)
  Re: Optimized curves  
From: Mark Wagner
Date: 22 Dec 1999 23:59:42
Message: <3861ac3e@news.povray.org>
Rune wrote in message <38613271@news.povray.org>...
>I'm trying to figure out a way to optimize curves.
>A curve of spheres positioned by a spline formula will be more bended some
>places than others and the distance between the spheres won't be the same.
>
>I need the spheres to be positioned so that there's a specified distance
>between them and so that the bending is also evenly distributed.


I needed something like this for a flythrough of the Grand Canyon I'm
working on.  Here's the solution I came up with that uses the SuperPatch
splines.  Note that since the spline is a cubic curve, but this code assumes
that it is linear, the spacing is not perfectly even, but it is very close
under most circumstances.  I hope this helps.

Mark

////////////////////////////////////////////////////////////////////////////
/////

 #declare NumPoints = 16;
 #declare SplineData = array[NumPoints]
 { <.6,1,-.1>,        <.54,1,-.6>,    <.5,.35,-.9>,  <.6,.35,-1.25>,
<.6,.35,-1.65>,
   <.2,.35,-1.90>,
<-.2,.35,-1.67>,<-.8,.35,-1.60>,<-1.2,.35,-1.4>,<-1.4,.35,-1.15>,
   <-1.625,.35,-.825>,<-2,.35,-.45>,
<-2.6,.35,-.55>,<-2.9,.35,-.75>,<-3.3,.35,-.9>,
   <-4.7,.35,-1.35>
 } /* Replace the values in SplineData with the positions of the control
points in your spline */
  /* Remember to update the value of NumPoints */

/* This determines the spacing of the control points */
#declare TotalDist = 0;
#declare counter = 1;
#declare Dist = array[NumPoints]
#declare Dist[0] = 0;
#while(counter < NumPoints)
 #declare temp = SplineData[counter]; /* Current control point */
 #declare temp2 = SplineData[counter-1]; /* Previous control point */
 #declare dist = vlength(temp-temp2);
 #declare TotalDist = TotalDist + dist;
 #declare Dist[counter] = TotalDist;
  #declare counter = counter + 1;
#end /* You may need to #undef temp and temp2 */

#declare path = spline{
 cubic_spline

 #declare counter = 0;
 #while(counter < NumPoints)
  Dist[counter]/TotalDist, SplineData[counter] /* If you want the spline to
be spaced out over an interval other than 0 to 1, modify this line by
multiplying Dist/TotalDist by some constant */
  #declare counter = counter + 1;
 #end
}


Post a reply to this message

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