POV-Ray : Newsgroups : povray.general : how do I make a closed spline? Server Time
6 Aug 2024 21:43:36 EDT (-0400)
  how do I make a closed spline? (Message 4 to 13 of 13)  
<<< Previous 3 Messages Goto Initial 10 Messages
From: Rune
Subject: To ABX and Ingo (was: how do I make a closed spline?)
Date: 17 Feb 2002 07:59:59
Message: <3c6fa94f@news.povray.org>
ABX and Ingo, thanks for your replies - I'm afraid they don't work though.

ABX, the message you took as basis for your reply was not correct. The cubic
spline used in spline{} is different from the cubic spline used in prisms.
Each segment in the spline is defined by all control points in the spline,
not just four. See the other messages in the thread "Cubic spline question"
for more information.

Ingo, you suggested adding an additional point in order to get a smooth
connection (one more point than in the method ABX talked about). However, a
test reveals that this doesn't work either.

In the code below is a spline that's supposed to be closed. I have also made
a blue graph that shows the curvature over the spline. The middle of the
graph is where the connection is. If you render the code with no
modifications you should see in the graph a blue dot high above the others
right where the connection is. This indicates a break in the curvature,
which means that the graph is not smooth. You can even see this with the
naked eye.

You can you add one more control point as Ingo suggested by uncommenting one
control point in the graph. Now the spline looks much more smooth to the
naked eye, but the blue graph shows that there's still a break in the
curvature. Even if you add yet another control point the break is still
there. So I think that it's practically impossible to get perfectly smoothly
connected curves with the cubic splines used in the spline{} feature, which
Mark Wagner says is the "natural cubic spline".

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 =
spline {
   cubic_spline
   // -2, <-2,0,2>, // P1 (uncomment to add a control point)
   -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 (uncomment to add one more control point)
}
#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

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: 17 Feb 2002 08:28:44
Message: <3C6FAE2F.203@webcon.de>
Rune wrote:
 >
>                 Even if you add yet another control point the break is still
> there. So I think that it's practically impossible to get perfectly smoothly
> connected curves with the cubic splines used in the spline{} feature, which
> Mark Wagner says is the "natural cubic spline".
> 


Mark Wagner wrote:
 > 6) The second derivative of the function is zero at the first and
 > last control points
 >

... so the only way to get it smooth is to define it in a way, that
the curvature goes down to zero near the first and last control points
(if you want to connect it at this points)

Natural spline is like a flexible piece of metal where the ends are
*not* forced into a specific direction but may turn as they want when
you bend it to go through all control points.
It so behaves like a real spline used to draw cuves, hence the name.


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.
It is difficult for me to express correct what I want to say, so lets
assume, your curve has N+1 control points labeled 0...N. Then you
close it at point (N-1), that is point(N-1)=point(1) and set 
point(N)=point(2) as well as point(0)=point(N-2)
As you are not using the first segment (0 through 1) as well as the 
last segment (N-1 through N) it is no longer of importance, what the
curvature does there.

hope, this is aplicable to your problem.

Hermann


Post a reply to this message

From: Dave Dunn
Subject: Re: how do I make a closed spline?
Date: 17 Feb 2002 10:02:18
Message: <3C6FC5D9.6F4E9BC8@aol.com>
Rune wrote:

> Using the cubic spline in the spline{} feature in POV-Ray 3.5, which rules
> should I follow in order to get a smoothly closed spline?

One thing I noticed in following this convoluted discussion is that the
"additional" points at the beginning and end of the cubic spline are supposed
to be (according to the docs) the third from the end for the first point and
the third from the beginning for the last. I have never had any trouble using
cubic splines (at least in prisms and lathes) using this method.


Post a reply to this message

From: Rune
Subject: Re: how do I make a closed spline?
Date: 17 Feb 2002 10:22:15
Message: <3c6fcaa7@news.povray.org>
"Dave Dunn" wrote:
> One thing I noticed in following this convoluted
> discussion is that the "additional" points at the
> beginning and end of the cubic spline are supposed
> to be (according to the docs) the third from the
> end for the first point and the third from the
> beginning for the last. I have never had any trouble
> using cubic splines (at least in prisms and lathes)
> using this method.

As pointed out before, the cubic spline in the spline{} feature is very
different from the cubic spline used in prisms and lathes. I am well capable
of closing a cubic spline in a prism or lathe, but to close the cubic spline
used in the spline{} feature is a completely different matter, which I have
not yet succeeded in (if it's possible at all).

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: how do I make a closed spline?)
Date: 17 Feb 2002 10:22:18
Message: <3c6fcaaa@news.povray.org>

> ... so the only way to get it smooth is to define
> it in a way, that the curvature goes down to zero
> near the first and last control points (if you want
> to connect it at this points)

Zero curvature at the start and at the end is not the issue. Zero curvature
*between* the start and the end is the issue! If you have two straight lines
in a 10 degree angle, both lines have zero curvature, but the connection
between them certainly isn't smooth. The problem is how to make the tangents
the same at the connection point.

> 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?

> hope, this is aplicable to your problem.

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.

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: Jaime Vives Piqueres
Subject: Re: To ABX and Ingo (was: how do I make a closed spline?)
Date: 17 Feb 2002 11:14:52
Message: <3c6fd6fc@news.povray.org>
#declare Spline =
spline {
   cubic_spline
   -5, < 0,0,0>, // P3
   -4, < 1,0,0>, // P4
   -3, < 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 
   13, <-2,0,2>, // P1
   14, <-1,0,0>, // P2
   15, < 0,0,0>, // P3
}

-- 
Jaime Vives Piqueres

La Persistencia de la Ignorancia
http://www.ignorancia.org


Post a reply to this message

From: Jaime Vives Piqueres
Subject: Re: To ABX and Ingo (was: how do I make a closed spline?)
Date: 17 Feb 2002 11:18:27
Message: <3c6fd7d2@news.povray.org>
Sorry, I sent it so fast by accident... I wanted to write this:

> 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...
>
> #declare Spline =
> spline {
>    cubic_spline
>    -5, < 0,0,0>, // P3
>    -4, < 1,0,0>, // P4
>    -3, < 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
>    13, <-2,0,2>, // P1
>    14, <-1,0,0>, // P2
>    15, < 0,0,0>, // P3
> }
> 

-- 
Jaime Vives Piqueres

La Persistencia de la Ignorancia
http://www.ignorancia.org


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: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 3 Messages Goto Initial 10 Messages

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