ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Mikael Sundqvist <mickep@gmail.com>
To: Hans Hagen <j.hagen@xs4all.nl>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Metapost: directionpoint gives unexpected point(?)
Date: Thu, 11 Feb 2021 17:41:55 +0100	[thread overview]
Message-ID: <CAHy-LL-wNX=S5n5xiLKxtHkF_9+rM0X9wv5buJ-JSzX3BX9=5w@mail.gmail.com> (raw)
In-Reply-To: <48eab08e-9a32-007d-3349-dd94ef53bbce@xs4all.nl>

Thanks for your investigation and extended example!

So, if I understand it correctly, the problem occurs where the
different circles are glued together with the .. construction.

I will wait to see if Alan or somebody else has an idea of a nice
solution to the problem.

/Mikael

On Thu, Feb 11, 2021 at 3:54 PM Hans Hagen <j.hagen@xs4all.nl> wrote:
>
> On 2/11/2021 2:45 PM, Mikael Sundqvist wrote:
> > 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.
> You need help from a metapost-mathematician to answer this (ping ...
> Alan). Here is a variant that shows you what happens (keep in mind that
> ".." is not always that useful with that amount of points):
>
> \starttext
> \startMPdefinitions{doublefun}
>
> def FOO(expr u) =
>
> 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);
> 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;
>
> % for phi=0 step 30 until 360:
> %     draw (directionpoint dir(phi) of p1) withpen pencircle scaled 4bp
> withcolor darkgreen;
> %     draw (directionpoint dir(phi) of p2) withpen pencircle scaled 4bp
> withcolor darkmagenta;
> % endfor ;
>
> drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of p1)
> -- endfor cycle withpen pencircle scaled 1bp withcolor darkgreen;
> drawarrow for phi=0 step 30 until 360: (directionpoint dir(phi) of p2)
> -- endfor cycle withpen pencircle scaled 1bp withcolor darkmagenta;
>
> drawarrow for phi=0 step 30 until 360:
>      ((directionpoint dir(phi) of p1) shifted (directionpoint dir(phi)
> of p2)) -- endfor cycle
> %     .5[directionpoint dir(phi) of p1, directionpoint dir(phi) of p2]
> -- endfor cycle
> withpen pencircle scaled 1bp 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);
> enddef ;
> \stopMPdefinitions
>
> \startMPpage[offset=4bp,instance=doublefun]
>      FOO(1cm);
> \stopMPpage
> \startMPpage[offset=4bp,instance=doublefun]
>      FOO(.8cm);
> \stopMPpage
> \startMPpage[offset=4bp,instance=doublefun]
>      FOO(.5cm);
> \stopMPpage
> \startMPpage[offset=4bp,instance=doublefun]
>      draw image (FOO(1/20)) scaled 5cm withpen pencircle scaled 1bp;
> \stopMPpage
> \stoptext
>
> You probably end up in the 1bp resolutions ... or something around the
> origin ... so maybe just calculate large and scale the result to what
> you want.
>
> Hans
>
> -----------------------------------------------------------------
>                                            Hans Hagen | PRAGMA ADE
>                Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>         tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2021-02-11 16:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 16:48 Mikael Sundqvist
2021-02-05 16:51 ` Mikael Sundqvist
2021-02-11 13:45   ` Mikael Sundqvist
2021-02-11 14:54     ` Hans Hagen
2021-02-11 16:41       ` Mikael Sundqvist [this message]
2021-02-12  8:35         ` Taco Hoekwater
2021-02-12  9:31           ` Mikael Sundqvist
2021-02-12  9:55             ` Taco Hoekwater
2021-02-12  9:53           ` Hans Hagen
2021-02-12 10:03             ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHy-LL-wNX=S5n5xiLKxtHkF_9+rM0X9wv5buJ-JSzX3BX9=5w@mail.gmail.com' \
    --to=mickep@gmail.com \
    --cc=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).