POV-Ray : Newsgroups : povray.general : how do I make a closed spline? Server Time
19 Nov 2024 18:15:05 EST (-0500)
  how do I make a closed spline? (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: Rune
Subject: how do I make a closed spline?
Date: 17 Feb 2002 03:56:48
Message: <3c6f7050$1@news.povray.org>
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?

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:
Subject: Re: how do I make a closed spline?
Date: 17 Feb 2002 06:08:47
Message: <7g2v6usa948nojl7tsqncosg81rr4ed7b7@4ax.com>
On Sun, 17 Feb 2002 09:55:16 +0100, "Rune" <run### [at] mobilixnetdk>
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?

considering that answer posted in
http://news.povray.org/3c6df3f6%241%40news.povray.org
is true then : if you want closed smooth spline drawed from M1 to Mn where M1
and Mn are inputs of spline then create spline with below rules:

spline{
cubic_spline
M0,V0
M1,V1
M2,V2
.............. // other points
Mn-1,V0 // note -1 is decreasing of idex n, not decreasing of value Mn
Mn,V1
Mn+1,V2  // note +1 is increasing of idex n, not increasing of value Mn
}

and additional conditions:
M1-M2=Mn-Mn+1 // +1 is again index increasing not value increasing
M1-M0=Mn-Mn-1 // as above but abou decreasing
M0<M1<M2<Mn-1<Mn<Mn+1 
and in other points list you can't have Mi index in rande M0..M2 or Mn-1..Mn+1

NOTE I'm not sure it is realy true, I just wrote it according to
http://news.povray.org/3c6df3f6%241%40news.povray.org
but looks smoth in below example:

#version 3.5;
light_source{-4+9*y 1}
camera{}

#local N=6;
#local A=array[N];
#local MinR=1;
#local MaxR=2;
#local R=.1;
#local S=seed(0);
#local Step=0.005;

#local Spline=spline{
  cubic_spline
  #local C=N;
  #while(C)
    #local C=C-1;
    #local A[C]=vrotate((rand(S)*(MaxR-MinR)+MinR)*x,z*C*360/N);
    C,A[C],
  #end
  -1,A[N-1],
  N,A[0]
  N+1,A[1]
};

#local C=N;
#while(C>0)
  sphere{Spline(C) R translate z*4 pigment{rgb 1}}
  #local C=C-Step;
#end

ABX


Post a reply to this message

From: ingo
Subject: Re: how do I make a closed spline?
Date: 17 Feb 2002 06:14:14
Message: <Xns91B87CC96B4AEseed7@povray.org>
in news:3c6f7050$1@news.povray.org 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?

By adding one extra point at the end of the spline.
Adding an extra point in front results in an error, somewhat unexpected 
to me.

---%<------%<---
#version 3.5;
global_settings {assumed_gamma 1.0}
camera {
  location  <0.5, 0.5,-2.0>
  look_at   <0.5, 0.5, 0.0>
}
light_source {<0, 0, -500> rgb 1}
#declare SPL=spline{
  cubic_spline
  //-2/4,<1,1,0>
  -1/4,<0,1,0>
   0/4,<0,0,0>
   1/4,<1,0,0>
   2/4,<1,1,0>
   3/4,<0,1,0>
   4/4,<0,0,0>
   5/4,<1,0,0>
   6/4,<1,1,0>
}
#declare N=500;
#declare I=0;
#while(I<N)
  sphere{SPL(I/N),0.05 pigment{rgb 1}}
  #declare I=I+1;
#end
---%<------%<---


Post a reply to this message

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

Goto Latest 10 Messages Next 3 Messages >>>

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