POV-Ray : Newsgroups : povray.advanced-users : normal to spline : Re: normal to spline Server Time
5 Jul 2024 15:33:49 EDT (-0400)
  Re: normal to spline  
From: triple r
Date: 11 Apr 2008 13:15:01
Message: <web.47ff9bfbe221823ae42298f0@news.povray.org>
"stevenvh" <nomail@nomail> wrote:

> I've been thinking :-)
> Finding the tangent axis is easy: that's r(t+1) - r(t-1), translated to r(t),
> right?
....
> So, what do you think?

I think you pretty much have it, and by now everyone else has pretty much hit
the nail on the head.  Had a small attack of real life these last couple days,
but here's the code anyway, and here's the OpenGL demo:

http://rsreusser.googlepages.com/nurbs3d.tar.gz

Fun to play around with, but not a great example of good coding.  I'm not sure
how to compile that on Windows, although it should be perfectly compatible.  On
Linux or Mac OS X it should be trivial.

 - Ricky

And just for kicks, this one calculates and plots the radius of curvature too:

camera{ location <3.5,2,-3.5> look_at <2.7,0,0> }
plane{y,0 pigment{rgb 1}}
background{rgb 0.5}
light_source{<25,25,-25>, rgb 1
    area_light 10*x,10*y,5,5 circular orient jitter
}

#declare sp=
    spline {
 natural_spline
 0.0, <0.0, 0,  0>,
 0.2, <1.0, 0.2, 0.5>,
 0.4, <2.0, 0.4,-0.9>,
 0.6, <3.5, 0.2, 1.0>,
 0.8, <4.0, 0.1,-0.3>,
 1.0, <5.0, 0.0, 0.0>
    }

cylinder{0,x,0.01 pigment{rgb x}}
cylinder{0,y,0.01 pigment{rgb y}}
cylinder{0,z,0.01 pigment{rgb z}}
union{
    #declare npt = 100;
    #declare c=0;
    #declare p0 = sp(0.0);
    #declare rad=0.02;
    #while(c<npt)
 #declare tv = c/(npt-1);
 #declare p1 = sp(tv);
 sphere{p0,rad pigment{rgb <tv,0,1-tv>}}
 #if(c>0) cylinder{p0,p1,rad pigment{rgb <tv,0,1-tv>}} #end
 #declare p0=p1;
 #declare c=c+1;
    #end
}
union{
    #declare points = array[4]{0.17, 0.37, 0.61, 0.85}
    #declare eps = 0.0001;
    #declare ncirc = dimension_size(points,1);
    #declare c=0;
    #while(c<ncirc)
 #declare tv=points[c];
 #declare pm=sp(tv-eps);
 #declare p0=sp(tv);
 #declare pp=sp(tv+eps);
 #declare drdt = (pp-pm)/(2.0*eps);
 #declare velocity = vlength(drdt);
 #declare tangent = vnormalize(drdt);
 #declare d2rdt2 = (pp-2.0*p0+pm)/(eps*eps);
 #declare accel = vlength(d2rdt2);
 #declare perp = vnormalize(d2rdt2-vdot(tangent,d2rdt2)*tangent);
 #declare crad = velocity*velocity/accel;
 #declare perp2 = vcross(tangent,perp);
 #declare e1=perp;
 #declare e2=perp2;
 #declare e3=tangent;
 #declare c0=p0+perp*crad;
 torus{crad,rad/2
     matrix < e1.x, e1.y, e1.z,
       e2.x, e2.y, e2.z,
       e3.x, e3.y, e3.z,
       c0.x, c0.y, c0.z >
 }
 cylinder{p0,p0+e1/5,rad/4 pigment{rgb x}}
 cylinder{p0,p0+e2/5,rad/4 pigment{rgb y}}
 cylinder{p0,p0+e3/5,rad/4 pigment{rgb z}}
 #declare c=c+1;
    #end
    pigment{rgb 2}
}


Post a reply to this message

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