[metapost] Re: tangent

Honza Prachar pracj3am at mbox.troja.mff.cuni.cz
Mon Jan 17 23:54:23 CET 2005


On Mon, 17 Jan 2005, Boguslaw Jackowski wrote:

> This foretells troubles:
> 
> 1. The solution need not to be unique; but this problem can be (iteratively
>    or recursively ;-) overcome.
> 2. What about singular points, such as the point 1/2 of p, where
>    p=(0,0) .. controls (1,1) and (0,1) .. (1,0) ? You should rather
>    accept the path going through z and such a peak, although the
>    path direction is singular there, namely: (0,0).
> 
> HP> I found solution using loop to determine right point, where tangent
> HP> and curve have same direction. But I do not believe it is the 
> HP> simpliest solution.
> 
> Could you present your solution?

z is in origin, curve is concave (see picture)

   |
-------------------------
   |     * * *
   |   *        *
   |  *           *
   | *             *
   |                *


path curve;
pair a;
numeric intersect, dir, t, delta;

delta:=0.1;
t:=length curve;
forever:
        a := point t of curve;
        a - (intersect,0) = whatever * (direction t of curve);
        exitif (intersect<0);
        t := t - delta;
        intersect := whatever;
endfor

draw origin -- (1.5[origin,a]);

--
`Honza` Prachar



More information about the metapost mailing list