POV-Ray : Newsgroups : povray.advanced-users : normal to spline : Re: normal to spline Server Time
5 Jul 2024 15:22:56 EDT (-0400)
  Re: normal to spline  
From: Tim Attwood
Date: 10 Apr 2008 22:13:48
Message: <47fec95c$1@news.povray.org>
> I've been thinking :-)
> Finding the tangent axis is easy: that's r(t+1) - r(t-1), translated to 
> r(t),
> right?
> Now, as long as r(t-1), r(t) and r(t+1) are not collinear, they define a 
> circle
> whose center (c) is the center of curvature in r(t), right? So my normal 
> vector
> is r(t) - c(t).
> Two points of attention:
> 1. r(t-1), r(t) and r(t+1) are collinear. In that case I would move c with 
> r,
> i.e. c(t) = c(t-1) + r(t) - r(t-1).
> 2. if the three points are nearly collinear the problem may be 
> ill-conditioned.
> I guess I could treat them as collinear if the radius of curvature becomes 
> very
> large.

Given three points you can define a plane, so if you take three
close together points from a path you can find the tangent.
Once you have the tangent, you can take a tangent point, and
two points from the path to define a plane that has a normal
in the direction of curve.

This should work in most situations, but may have odd behavior
along a straight line. You may also need to check the direction
of the normal and reverse it if the curve is flipped, though this
sample doesn't seem to misbehave without that sort of check.

#include "colors.inc"
#include "math.inc"
#include "transforms.inc"

#default {finish{ambient 0.7}}
// --- camera, lights & 
background ------------------------------------------
camera {
   location  <0.0, 1, -4.0>
   direction 1.5*z
   right     x*image_width/image_height
   look_at   <0.0, 0.5,  0.0>
}

background {Gray85}

light_source {
  <-30, 30, -30>
  color rgb <1, 1, 1>
}

// ---  
macros ---------------------------------------------------------------
#declare Path_Spline = spline {
   natural_spline
   0, <-2,0,0>
   1, <-1,0,0>
   2, <-0.5,0.5,0>
   3, <0,1,1>
   4, <0.5,0.5,0>
   5, <1,0,0>
   6, <2,0,0>
};

#macro Path_Normal(N, rez)
   #local P1 = Path_Spline(N-rez);
   #local P2 = Path_Spline(N);
   #local P3 = Path_Spline(N+rez);
   #local HPerp = VPerp_To_Plane(vnormalize(P2-P1),vnormalize(P3-P2));
   #local Perp = VPerp_To_Plane(vnormalize(HPerp-P2),vnormalize(P3-P2));
   (Perp)
#end

// show spline
#local C = 0;
#while (C <= 6)
   sphere{Path_Spline(C),0.01 pigment {Yellow}}
   #local C=C+0.005;
#end

// inside of curve
#local C = 0.5;
#while (C <= 5.5)
   #local Perp = Path_Normal(C,0.1);
   sphere {Path_Spline(C)+Perp/10,0.01 pigment{Orange}}
   #local C=C+0.005;
#end


Post a reply to this message

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