POV-Ray : Newsgroups : povray.general : how do I make a closed spline? Server Time
6 Aug 2024 21:40:24 EDT (-0400)
  how do I make a closed spline? (Message 11 to 13 of 13)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Rune
Subject: Re: To ABX and Ingo (was: how do I make a closed spline?)
Date: 17 Feb 2002 11:29:51
Message: <3c6fda7f@news.povray.org>
"Jaime Vives Piqueres" wrote:
> > Not elegant, I know, but it works for me (I had the
> > same problem here recently). One more point at each
> > end works even better...

Yes, I know, adding ridiculously many points at the ends makes the error
ridiculously small... ;)

But as you say, it's not very elegant. I hope the catmull-rom spline type
(the cubic spline used in prisms and lathes) will be added as an alternative
to this natural cubic spline which is the one currently used in the spline{}
feature. The catmull-rom spline always connects 100% smooth with only one
extra point at each end besides the connection point.

Anyway, I guess this solution is acceptable for now...

Rune
--
3D images and anims, include files, tutorials and more:
Rune's World:    http://rsj.mobilixnet.dk (updated Feb 16)
POV-Ray Users:   http://rsj.mobilixnet.dk/povrayusers/
POV-Ray Webring: http://webring.povray.co.uk


Post a reply to this message

From: Rune
Subject: Re: To ABX and Ingo (was: how do I make a closed spline?)
Date: 17 Feb 2002 11:36:11
Message: <3c6fdbfb@news.povray.org>
By the way, I think you missed the big jump in t values I had from 0.2 to
0.8. The spline should actually look like this:

spline {
   cubic_spline
   -10,< 0,0,0>, // P3
   -9, < 1,0,0>, // P4
   -8, < 2,0,2>, // P5
   -2, <-2,0,2>, // P1
   -1, <-1,0,0>, // P2
    0, < 0,0,0>, // P3 red joining point
    1, < 1,0,0>, // P4
    2, < 2,0,2>, // P5
    8, <-2,0,2>, // P1
    9, <-1,0,0>, // P2
   10, < 0,0,0>, // P3 red joining point
   11, < 1,0,0>, // P4
   12, < 2,0,2>, // P5
   18, <-2,0,2>, // P1
   19, <-1,0,0>, // P2
   20, < 0,0,0>, // P3
}

By the way 2, I called the joining point "red" even though the entire spline
is red in the code I posted - D'oh! A leftover from my earlier tests...

Rune
--
3D images and anims, include files, tutorials and more:
Rune's World:    http://rsj.mobilixnet.dk (updated Feb 16)
POV-Ray Users:   http://rsj.mobilixnet.dk/povrayusers/
POV-Ray Webring: http://webring.povray.co.uk


Post a reply to this message

From: Hermann Voßeler
Subject: Re: how do I make a closed spline?)
Date: 19 Feb 2002 12:23:11
Message: <3C728820.7060608@webcon.de>
Rune wrote:

>>Thus, a trick would be to "go round byond the end point".
>>I.e to use a additional control point that is identical with
>>the second point on the curve.
>>
> 
> I thought this was exactly what I had done in my example code?
> I didn't understand you. I would appreciate if you could look at my example
> code and show me how to change it to get a smooth connection.

Sorry, Rune, indeed I was in hurry and overlooked, that you had added
an additional point at the start. So this was my fault.

In cases where it has to bee *realy* smooth, one additional point 
often is not sufficient. I found myself using sometimes three or four.

Some weeks ago, I had to create lots of closed splies, so I wrote a
short macro, see below enclosed in your example.

Hermann



#macro nat_closed(o)
   #if (o<=0)
     #error "number of additional control points needs be >0\n"
   #end
   #declare u_nr=0;
   #declare o_nr=0;
   #declare firstPts=array[o+1];
   #declare firstVec=array[o+1];
   #declare lastPts =array[o];
   #declare lastVec =array[o];
   #declare over=o;
   spline { cubic_spline
#end
#macro CP(pt,V)
   pt, V,
   #if (u_nr<over+1)
     #declare firstPts[u_nr]=pt;
     #declare firstVec[u_nr]=V;
   #end
     #declare lastPts[o_nr]=pt;
     #declare lastVec[o_nr]=V;
   #declare u_nr=u_nr+1;
   #declare o_nr=mod(o_nr+1,over);
#end
#macro join_it(join_at)
   #if (u_nr<over+1)
     #error concat("only ",str(u_nr-1,0,0)," additional control points 
possible with this data\n")
   #end
   #local i=0;
   #while(i<over+1)
     join_at+firstPts[i]-firstPts[0], firstVec[i],
     #local i=i+1;
   #end
   #local i=0;
   #while(i<over)
     firstPts[0]+lastPts[i]-join_at, lastVec[i],
     #local i=i+1;
   #end
   }// end generated spline declaration
#end



camera {location 4*y look_at 0 translate z}
light_source {1000*y, color 1}
plane {y, 0 pigment {checker color rgb 1.0, color rgb 0.9}}


#declare Spline = nat_closed(3)   // <--- No of additional control pts
    CP( 0, < 0,0,0>) // P3 red joining point
    CP( 1, < 1,0,0>) // P4
    CP( 2, < 2,0,2>) // P5

    CP( 8, <-2,0,2>) // P1
    CP( 9, <-1,0,0>) // P2
join_it(10)


#declare C = 0;
#while (C<=200)
    #declare V = C/20;
    sphere {Spline(V), 0.02 pigment {color <1,0,0>}}
    #declare C = C+1;
#end
#declare C = 0;
#declare Cm = 400;
#while (C<=Cm)
    #declare V = C/Cm;
    #declare T0 = mod((C-1)/40+5,10);
    #declare T1 = mod( C   /40+5,10);
    #declare T2 = mod((C+1)/40+5,10);
    sphere {
       <-2+4*C/Cm
          0,
          1+100*vlength(
             +(Spline(T1)-Spline(T0))
             -(Spline(T2)-Spline(T1))
          )
       >
         0.02
       pigment {color <0,0,1>}}
    #declare C = C+1;
#end


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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