|
![](/i/fill.gif) |
"Tim Attwood" <tim### [at] comcast net> wrote:
> 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
Thanks, Tim.
While I agree with your code, I'm a bit puzzled by the results.
I changed point 3 of the spline to <0,1,0>, so that the spline lies in the Z=0
plane.
First observation: if the spline lies in the Z=0 plane, so should the orange
locus, but it doesn't. I don't know why.
OTOH the orange curve is discontinuous where you expect it, i.e. at the
inflection points of the spline.
I also would write (P3-P1) instead of (P3-P2) in the calculation of Perp, but
since P1, P2 and P3 are nearly collinear this shouldn't make much difference
(and it doesn't).
Thanks again.
Steven
(Learned this lesson: "VPerp_To_Plane" :-))
Post a reply to this message
|
![](/i/fill.gif) |