[NTG-context] Metapost: directionpoint gives unexpected point(?)
Mikael Sundqvist
mickep at gmail.com
Thu Feb 11 14:45:52 CET 2021
Hi,
since I already started this thread, I continue here. My metapost code
is still not always working, and I do not understand what is going
wrong. In the example below, I draw two curves of constant width (p1
and p2), one rotated 180 degrees around the origin. Then I draw the
curve (p3), constructed as follows: for each direction (phi), find the
point of p1 and p2 which correspond to it, and add those points. This
should result in a circle, and with the code I paste it does (hooray!
see the file minkowski-good.pdf). BUT, it seems very unstable. If I
change u to 0.5cm instead of 1cm, it breaks down (see
minkowski-bad.pdf). If I loop over more angles phi (say step 2 instead
of step 30), it gets wrong.
Any ideas are welcome.
/Mikael
\starttext
\startMPpage[offset=4bp,instance=doublefun]
u:=1cm;
path p[];
% This defines the reulleaux curves
% p[0] is a "base" reulleaux curve
path cl,cs,rl ;
z0 = (0,6/sqrt(3)*u);
z1 = z0 rotated 120;
cl := (fullcircle scaled 4u) shifted z0;
cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
cs := (fullcircle scaled 16u) shifted z1;
cs := cs cutafter point 1/6 along cs;
p[0] := cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs
rotated 240) .. (cl rotated 240) .. cycle;
% the first curve (darkyellow)
p[1] := p[0] rotated 27 shifted (-10u,2u);
draw p1 withpen pencircle scaled 2bp withcolor darkyellow;
% the second curve (darkblue)
p[2] := p[1] rotated 180;
draw p2 withpen pencircle scaled 2bp withcolor darkblue;
% the minkowski sum (darkred) of the reulleaux curves p1 and p2.
p3 := for phi=0 step 30 until 360: ((directionpoint dir(phi) of p1)
shifted (directionpoint dir(phi) of p2)) .. endfor cycle;
draw p3 withpen pencircle scaled 2bp withcolor darkred;
% We give one direction as example
% These are merely here to show the construction of the curve
% But they also show what is going wrong
direx:=40;
z11=directionpoint dir(direx) of p1;
z22=directionpoint dir(direx) of p2;
p4 = ((-u,0)--(u,0)) rotated direx;
% These arrows should be tangent
drawarrow p4 shifted z11;
drawarrow p4 shifted z22;
drawarrow p4 shifted (z11 shifted z22);
% Draw the parallelogram.
draw origin -- z11 dashed evenly;
draw origin -- z22 dashed evenly;
draw z11 -- (z11 shifted z22) dashed evenly;
draw z22 -- (z11 shifted z22) dashed evenly;
dotlabel.top("$O$",origin);
\stopMPpage
\stoptext
On Fri, Feb 5, 2021 at 5:51 PM Mikael Sundqvist <mickep at gmail.com> wrote:
>
> Hi,
>
> I was too quick to push send. This must be some rounding error.
> Changing the instance fixes the problem. Sorry for the noise.
>
> /Mikael
>
> On Fri, Feb 5, 2021 at 5:48 PM Mikael Sundqvist <mickep at gmail.com> wrote:
> >
> > Hi,
> >
> > I get sometimes the wrong directionpoint. In the example below it
> > works for all values of direx except between 0 and 90. If I put direx
> > to something in this interval, it seems that the point between cs and
> > cl are chosen.
> >
> > Is there a better way to construct the paths not to get this problem?
> > Or some other way out?
> >
> > /Mikael
> >
> > \starttext
> > \startMPpage[offset=3bp]
> > u:=1cm;
> > path cl,cs,rl,p[];
> > z0 = (0,6/sqrt(3)*u);
> > z1 = z0 rotated 120;
> > cs := (fullcircle scaled 16u) shifted z1;
> > cs := cs cutafter point 1/6 along cs;
> > cl := (fullcircle scaled 4u) shifted z0;
> > cl := cl cutbefore point 1/6 along cl cutafter point 2/6 along cl;
> >
> > p[0] = cs .. cl .. (cs rotated 120) .. (cl rotated 120) .. (cs rotated
> > 240) .. (cl rotated 240) .. cycle;
> >
> > draw p[0];
> >
> > drawarrow cs withcolor darkblue;
> > drawarrow cl withcolor darkred;
> >
> > direx=300;
> > z11=directionpoint dir(direx) of p[0];
> > drawarrow ((-u,0)--(u,0)) rotated direx shifted z11;
> >
> > \stopMPpage
> > \stoptext
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minkowski-good.pdf
Type: application/pdf
Size: 5536 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20210211/69616165/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minkowski-bad.pdf
Type: application/pdf
Size: 5399 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20210211/69616165/attachment-0001.pdf>
More information about the ntg-context
mailing list