POV-Ray : Newsgroups : povray.advanced-users : normal to spline : Re: normal to spline Server Time
5 Jul 2024 16:30:04 EDT (-0400)
  Re: normal to spline  
From: triple r
Date: 9 Apr 2008 11:35:00
Message: <web.47fce193e221823ae42298f0@news.povray.org>
"stevenvh" <nomail@nomail> wrote:
> Hi,
> is there a way to find the normals to a (non-linear) spline at calculated
> points?
> TIA
> Steven

I would recommend finite differences.  The fist derivative is the tangent.  So
if r(t) is the vector defined by the spline, the first derivative is

dr/dt = ( r(t+eps) - r(t-eps) ) / (2*eps)

t = (dr/dt) / |dr/dt|

where epsilon is some small constant.  So normalize the result and you have a
tangent vector.  At this point all you really need to do is cross the tangent
vector with a random vector and you should have a normal vector.  However, if
you want the normal vector in the direction of the curvature, you need to
calculate the second derivative with a finite difference.  As long as the
spline isn't a straight line this should not be collinear with the tangent:

d2r/dt2 = ( r(t+eps) - 2.0*r(t) + r(t-eps) ) / (eps^2)

The problem is that this won't be perpendicular to the tangent vector.  So the
solution is to define the normal vector by subtracting the component of the
second derivative that lies along the tangent vector.  Then all you have is a
vector that's perpendicular to the tangent vector.  Thus

n = d2r/dt2 - t * vdot( d2r/dt2, t )

n = n / |n|

Let me know if that's not clear enough.  I hope that's right, but someone asked
me this before so I even have an OpenGL demo with NURBS if you're interested.

 - Ricky


Post a reply to this message

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