POV-Ray : Newsgroups : povray.general : Help on Splines Server Time
29 Nov 2024 17:49:19 EST (-0500)
  Help on Splines (Message 1 to 6 of 6)  
From: Chrisir
Subject: Help on Splines
Date: 20 Jul 2005 04:05:02
Message: <web.42de04fd3147da22c869c55d0@news.povray.org>
Hello!

I am looking for a function that helps me with splines.

I want to give the function the ***exact*** start point (x1,y1,z1) and end
point (x2,y2,z2) of an spline and the height (h) of it - nothing more.



All other things should be figured out by the function.
The spline stands in a right angle to plane below.


The stuff in the function should be something similar to what you see below
the message.
A sphere i moved along the spline.

The Problem is to get the points ***exactly*** to a given start and end
position (x,y,z). I'd line to begin the first sphere exact at (above) the
star-point xyz.

I really like to have a functon doing it.

Thanks a lot!

Chrisir


// +++++++++++++++++++++++++++++++++++++++++++++++++++


#declare MySpline =
  spline {
    cubic_spline
    -0.25,<-1,  -1.6,-.85>
   0.10, <-.87,1.05,-.85>
   0.80, <.64, 1.1,.6>
   1, <1.8, -1.4, 1.1>
  }

#declare ctr = -.3;
#while (ctr < 1.2)
  sphere {
    MySpline(ctr), .05
    pigment { rgb <0.5,1,0> }
  }
  #declare ctr = ctr + 0.01;
#end

// +++++++++++++++++++++++++++++++++++++++++++++++++++


Post a reply to this message

From: Jim Charter
Subject: Re: Help on Splines
Date: 20 Jul 2005 10:54:02
Message: <42de658a$1@news.povray.org>
Chrisir wrote:

I think it's easiest to use a type other than cubic_spline

something like:

#macro U_Spline ( Start, Height, End )

         spline {
                natural_spline
                0/2 Start
                1/2 ((End-Start)/2)+<0,Height,0>
                2/2 End
         }

#end

//usage
#local Myspline = U_Spline ( <0,0,0>, 3, <2,1,1> );

#local Grain=30;
#local I=0;#while(I<Grain)
         sphere { 0, .1
                pigment { rgb <1,0,1> }
                finish { ambient 1 }
                translate Myspline(I/Grain)
         }
#local I=I+1;#end


Post a reply to this message

From: Mike Williams
Subject: Re: Help on Splines
Date: 20 Jul 2005 13:11:33
Message: <M$3QgEA9Mo3CFwJH@econym.demon.co.uk>
Wasn't it Chrisir who wrote:
>
>
>Hello!
>
>I am looking for a function that helps me with splines.
>
>I want to give the function the ***exact*** start point (x1,y1,z1) and end
>point (x2,y2,z2) of an spline and the height (h) of it - nothing more.
>

>
>All other things should be figured out by the function.
>The spline stands in a right angle to plane below.
>
>
>The stuff in the function should be something similar to what you see below
>the message.
>A sphere i moved along the spline.
>
>The Problem is to get the points ***exactly*** to a given start and end
>position (x,y,z). I'd line to begin the first sphere exact at (above) the
>star-point xyz.
>
>I really like to have a functon doing it.

How about a macro? As well as the start and end point, I've added a
Height parameter because it would be tricky to adjust the height with a
"scale" operation if the start and end point were at different heights.


#macro USpline(P1,P2,Height)
  spline {
    cubic_spline
    -1,P1-y
     0,P1
     0.5, (P1+P2/2 + y*Height)
     1,P2
     2,P2-y
  }
#end

#declare MSpline = USpline(<-.87,1.05,-.85>, <.64, 1.1,.6>, 0.5)

#declare ctr = 0;
#while (ctr < 1)
  sphere {
    MSpline(ctr), .05
    pigment { rgb <0.5,1,0> }
  }
  #declare ctr = ctr + 0.01;
#end


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Mike Williams
Subject: Re: Help on Splines
Date: 20 Jul 2005 13:24:13
Message: <hvlbEIA0io3CFwN5@econym.demon.co.uk>
Wasn't it Chrisir who wrote:
>
>
>Hello!
>
>I am looking for a function that helps me with splines.
>
>I want to give the function the ***exact*** start point (x1,y1,z1) and end
>point (x2,y2,z2) of an spline and the height (h) of it - nothing more.
>

>
>All other things should be figured out by the function.
>The spline stands in a right angle to plane below.
>
>
>The stuff in the function should be something similar to what you see below
>the message.
>A sphere i moved along the spline.
>
>The Problem is to get the points ***exactly*** to a given start and end
>position (x,y,z). I'd line to begin the first sphere exact at (above) the
>star-point xyz.
>
>I really like to have a functon doing it.
>
>Thanks a lot!
>
>Chrisir

I'm not sure if it's possible to do it with one function, but here's a
way to do it with three functions. The MakeFun macro creates the three
functions Fx(), Fy() and Fz().

// Fh defines the overall shape of the curve
// Choose a function that is:
//  zero when ctr=0
//  zero when ctr=0
//  one  when ctr = 0.5
// here are two possibilites - comment out the one you don't want

#declare Fh = function(a){sin(a*pi)}
//#declare Fh = function(t){4*(t-t*t)}

// Define the macro that creates the functions
#macro MakeFun(P1,P2,Height)
  // extract the coordinates of the points
  // because you can't use vectors in function declarations
  #local P1x= P1.x;
  #local P2x= P2.x;
  #local P1y= P1.y;
  #local P2y= P2.y;
  #local P1z= P1.z;
  #local P2z= P2.z;
  // Undefine the functions, in case we want to call the
  // macro more than once
  // (redeclaring functions is illegal)
  #undef Fx
  #undef Fy
  #undef Fz
  // declare the functions
  #declare Fx = function(a){P1x+(P2x-P1x)*a}
  #declare Fy = function(a){P1y+(P2y-P1y)*a + Fh(a)*Height}
  #declare Fz = function(a){P1z+(P2z-P1z)*a}
#end

// Invoke the macro to create the functions
MakeFun(<-.87,1.05,-.85>, <.64, 1.1,.6>, 1.5)

#declare ctr = 0;
#while (ctr < 1)
  sphere {
    <Fx(ctr),Fy(ctr),Fz(ctr)>, .05
    pigment { rgb <0.5,1,0> }
  }
  #declare ctr = ctr + 0.01;
#end


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Chrisir
Subject: Re: Help on Splines
Date: 20 Jul 2005 14:20:01
Message: <web.42de94d39b2676dc869c55d0@news.povray.org>
Hello!

I did check your second posting, only the first yet.


Well, since I'd like
to paint ***a lot*** of U-arcs, the point is too
have ***only one*** line of Code for each U-arc.

One U-arc consists of the spline defintion
and a while-routine to put spheres on that
spline (to get the actual arc).

I therefore build a Macro for the second step
[a while-routine to put spheres on that
spline (to get the actual arc)] as well:

#macro Use_USpline(P1,P2,Height)

        #declare MSpline = USpline(P1,P2,Height)
        #declare TestSphereRadius = 0.02;
        #declare ctr = 0;

        #while (ctr < 1)
          sphere {
            MSpline(ctr), .05
            pigment { rgb <0.5,1,0> }
          }
          #declare ctr = ctr + 0.01;
        #end   // end of while

        ShowPoint(P1)

        ShowPoint(P2)

#end  // end of macro



Now it's possible to have only one line for
one U-arc:
Use_USpline(<-.87,1.05,-.85>, <.64, 1.1,.6>, 0.5)

that's how far i am as for now.

Thanks a lot for your enormous efforts!

Greetings

Chrisir



****
More complete Code:


// ================

// For Test purposes
#macro ShowPoint(P1)

        #declare TestSphereRadius = 0.02;

        // Capped Cylinder, closed [or open ended]
        // cylinder { <END1>, <END2>, RADIUS [open] }
        //  END1 = coord of one end of cylinder
        //  END2 = coord of other end
        // RADIUS = size of cylinder
        // open = if present, cylinder is hollow, else capped

        cylinder {
          <P1.x-0.4,P1.y,P1.z>, <P1.x+0.4,P1.y,P1.z>, TestSphereRadius
          // open
        }


        cylinder {
          <P1.x,P1.y-.4,P1.z>, <P1.x,P1.y+.4,P1.z>, TestSphereRadius
          // open
        }

        cylinder {
          <P1.x,P1.y,P1.z-.4>, <P1.x,P1.y,P1.z+.4>, TestSphereRadius
          // open
        }

#end    // end of macro

// ================

#macro USpline(P1,P2,Height)
  spline {
    cubic_spline
    -1,P1-y
     0,P1
     0.5, (P1+P2/2 + y*Height)
     1,P2
     2,P2-y
  }
#end  // end of macro

#macro Use_USpline(P1,P2,Height)

        #declare MSpline = USpline(P1,P2,Height)
        #declare TestSphereRadius = 0.02;
        #declare ctr = 0;

        #while (ctr < 1)
          sphere {
            MSpline(ctr), .05
            pigment { rgb <0.5,1,0> }
          }
          #declare ctr = ctr + 0.01;
        #end   // end of while

        ShowPoint(P1)

        ShowPoint(P2)

#end  // end of macro

Use_USpline(<-.87,1.05,-.85>, <.64, 1.1,.6>, 0.5)
Use_USpline(<.87,1.5,1.85>, <2.64, 1.1,.6>, 1.5)
Use_USpline(<.87,.05,.85>, <.4, 1.1,.6>, 1.5)


Post a reply to this message

From: Chrisir
Subject: Re: Help on Splines
Date: 20 Jul 2005 14:25:00
Message: <web.42de96b19b2676dc869c55d0@news.povray.org>
Well, I guess my wording was wrong since i am new to povray.
When I wrote "function" I meant what I now know is called "macro".

Sorry!

Thx!


Post a reply to this message

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