POV-Ray : Newsgroups : povray.advanced-users : Re: Align objects ton spline ? Server Time
31 Oct 2024 23:28:39 EDT (-0400)
  Re: Align objects ton spline ? (Message 1 to 4 of 4)  
From: ABX
Subject: Re: Align objects ton spline ?
Date: 28 Jan 2004 12:17:39
Message: <efrf10dsr880ef7oht86ogf7kspd4d26l8@4ax.com>
On Wed, 28 Jan 2004 18:15:02 +0100, LightBeam <s.f### [at] tiscalifr> wrote:
> Hello, here is my problem:
> I started with a spline to create a kind of link but I have no idea how 
> to make the cylinders follow 'nicely' the curve.. What is the solution 
> to make them aligned and rotated to fit the spline/curve ? (Joined the 
> source)

See splinefollow animation sample in POV-Ray 3.5 for reference.

> Please help me...

Help others using correct group for binaries :-)

ABX


Post a reply to this message

From: LightBeam
Subject: Re: Align objects ton spline ?
Date: 28 Jan 2004 13:07:11
Message: <4017fa4f$1@news.povray.org>
Thank you... but doesn't help :-\


Post a reply to this message

From: Mike Williams
Subject: Re: Align objects ton spline ?
Date: 28 Jan 2004 14:33:38
Message: <WOZt$LA84AGAFwIE@econym.demon.co.uk>
Wasn't it LightBeam who wrote:
>Hello, here is my problem:
>I started with a spline to create a kind of link but I have no idea how 
>to make the cylinders follow 'nicely' the curve.. What is the solution 
>to make them aligned and rotated to fit the spline/curve ? (Joined the 
>source) Please help me...

I'd do it by using Reorient_Trans to rotate the cylinders. The cylinders
are currently pointing in the z direction and we want them aligned along
the spline, so we reorient them like this

#include "transforms.inc"

  cylinder {<0.0, 0.0, -0.02><0.0, 0.0, 0.02>0.07
  transform {Reorient_Trans(z,Direction)}

An alternative method would be to create the cylinder already oriented
in the required direction. This works with simple shapes like cylinders
but with a complex shape use Reorient_Trans.

  cylinder {-0.02*vnormalize(Direction),0.02*vnormalize(Direction),0.07



But we need to find the direction of the spline. This can normally be
achieved by taking the difference two locations from the spline, like
this:

  #declare Direction = (Spline(ctr+0.001) -Spline(ctr-0.001));



Unfortunately, this gives a problem if you try to use it on a point
that's off the end of the spline, because it returns the zero direction
and you can't use that in Reorient_Trans. This can either be solved by
treating points that are off the end of the spline as a special case

  #declare Direction = (Spline(ctr+0.001) -Spline(ctr-0.001));
  #if (vlength(Direction) = 0)
    #declare Direction = x;
  #end

or by confining yourself to only using points that are on the spline,
noting this paragraph in the documentation "Note: Because of the way
cubic_splines are defined: the first and last points are tangents rather
than points on the spline, cubic_spline interpolation is only valid
between the second and next-to-last points."

  #declare ctr = 0.1;
  #declare Spacing = 0.01;
  #while (ctr < 0.4)



Here's the whole thing put together using only the valid region of the
cubic_spline


camera {location <0.0, 2.0, -2.0> look_at 0.0}

light_source {<100.0, 300.0, -50.0>1.0}

plane {y, -0.5 pigment {rgb 0.7}}

#declare Spline =
   spline {
     cubic_spline
     0.00, <1,0,0>
     0.10, <0,0,1>
     0.20, <-1,0,0>
     0.30, <0,0,-1>
     0.40, <0,0,0>
     0.50, <1,0,0>
   }

#declare ctr = 0.003;
#declare Spacing = 0.001;
#while (ctr < 0.7)
         sphere {0.0, 0.03
         translate Spline(ctr)
         pigment {rgb 0.3}
         }
   #declare ctr = ctr + Spacing;
#end

#declare ctr = 0.1;
#declare Spacing = 0.01;
#while (ctr < 0.4)
   #declare Direction = (Spline(ctr+0.001) -Spline(ctr-0.001));
   cylinder {-0.02*vnormalize(Direction),0.02*vnormalize(Direction),0.07
      translate Spline(ctr)
      pigment {rgb 0.3}
   }
   #declare ctr = ctr + Spacing;
#end


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Jim Charter
Subject: Re: Align objects ton spline ?
Date: 28 Jan 2004 18:57:03
Message: <40184c4f$1@news.povray.org>
LightBeam wrote:


> 
> #declare ctr = 0.003;
> #declare Spacing = 0.01;
> #while (ctr < 0.7)
>         cylinder {<0.0, 0.0, -0.02><0.0, 0.0, 0.02>0.07
>         translate Spline(ctr)
>         pigment {rgb 0.3}
>         }
>   #declare ctr = ctr + Spacing;
> #end
>
As a rough and ready answer I sometimes do this:

#local B=0; #while ( B+1 < 50    )
      #local Pt = SplineA( B/50 );
      #local Pt2 = SplineA( (B+1)/50 );
      cylinder { Pt, Pt2, .0055 pigment { rgb < 0, 1, 0 > } }
 
    #local B=B+1;#end


Post a reply to this message

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