POV-Ray : Newsgroups : povray.newusers : POC crashes using spline : Re: POC crashes using spline Server Time
7 Jul 2024 08:16:23 EDT (-0400)
  Re: POC crashes using spline  
From: Reactor
Date: 11 Jan 2010 00:05:01
Message: <web.4b4ab09421d3af2292f1d6f50@news.povray.org>
"geogeo" <geo### [at] mecolcouk> wrote:
> "geogeo" <geo### [at] mecolcouk> wrote:
> > I've been battling with this for some hours now so thought it time to cry Help!
> > Trying to place objects along a helix using a spline, code as below. When I
> > activate the the commented out bit (last section of code) POV crashes every
> > time. Any ideas anyone?
> > Thanks, Geo
> >
> > // generate helix -----------------------------------------
> > #declare R1=3.5;     //outer radius
> > #declare F1=0.2;     //point spacing
> > #declare N=100;      //points on helix   200
> > #declare H=20;       //tightness
> >
> > //set up helical spline -------------------------------------------
> > #declare P2 = array[N][3];
> > #declare j=0;
> > #while (j<N)
> >  #declare P2[j][0] = (j*H/N)-(H/2);
> >  #declare P2[j][1] = R1*sin(F1*j);
> >  #declare P2[j][2] = R1*cos(F1*j);
> >  #declare j=j+1;
> > #end
> >
> > #declare j=0;
> > #while (j<N)
> >   #declare helix_spline1 =
> >   spline { natural_spline
> >   j/N, <P2[j][0],P2[j][1],P2[j][2]>
> >   #debug concat("helix = ", str(j/N,0,-1)," ", str(P2[j][0],0,-1)," ",
> > str(P2[j][1],0,-1)," ",  str(P2[j][2],0,-1), "\n")
> >   #declare j=j+1;
> >          }
> > #end
> >
> > //place objects along helix ---------------------------------------
> > #declare helix_object =
> >  sphere { <0,0,0>, 0.2
> >           texture {pigment { Green }  finish { ambient 0.1 diffuse 0.5  phong
> > ..4}
> >                   }
> >         }
> >
> > /*
> >  #declare cnt=0;
> >  #while (cnt<1)
> >   object { helix_object
> >           translate helix_spline1(cnt   )
> >          }
> >   #declare cnt = cnt + 0.1;
> >  #end
> > */
>
> Have now resolved this, seems the term natural_sline which I got from a tutorial
> is the problem, changed it to quardratic_spline then no more crashes.
> However the while loop surrounding the spline is flawed and doesn't define the
> spline at all but a load of single point splines! Can't yet see a way to do this
> without tediously defining each point - any ideas anyone?
> Geo



Your loop body has some parts that are supposed to be loop invariant.  The
declaration and closing brace should be outside of the loop.  Note that this may
require trickery to get your commas right.
Consider:

#declare j=0;
  #declare helix_spline1 =
  spline { natural_spline
#while (j<N)
  j/N, <P2[j][0],P2[j][1],P2[j][2]>
  #debug concat("helix = ", str(j/N,0,-1)," ", str(P2[j][0],0,-1)," ",
str(P2[j][1],0,-1)," ",  str(P2[j][2],0,-1), "\n")
  #declare j=j+1;
#end
   } // closing brace outside


Your old code was just redefining helix_spline1 as a single point spline
repeatedly instead of building the whole spline from the array.

-Reactor


Post a reply to this message

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