在 metapost 中获取笔划的路径

在 metapost 中获取笔划的路径

假设我有一些相当简单的 metapost 代码:

outputformat := "svg";
outputtemplate := "%j-%c.svg";

beginfig(1);
  pickup pencircle scaled .2in yscaled .2 rotated 30;    
  u := 36;

  z0 = (0,0);
  z1 = (0,1u);
  z2 = (1u,0);
  z3 = (0,-1u);
  z4 = (-1u,0);

  draw z1 -- z3 withcolor .7white;
  draw z2 -- z4 withcolor .7white;

  dotlabels.top(0,1,2,3,4);

endfig;    
end

这将输出一个与原点相交的十字图形z0

仅作为说明性示例,假设我想使两个笔画之间的交点变得平滑:我需要两个笔画之间的交点,然后是沿路径的点,如下所示:

在此处输入图片描述

红点为交点,蓝点为笔触路径。

我觉得如果能够获得笔触的路径,那么实现我的想法就非常容易了。

答案1

下面是如何使用 new 运算符的示例envelope

outputformat := "svg";
outputtemplate := "%j-%c.svg";

beginfig(1);

    % pickup pencircle scaled .2in yscaled .2 rotated 30;    

    % this only works with a polygonal pen, so lets make a close approximation to pencircle...
    pen knib;
    knib = makepen((for t=0 upto 30: right scaled 7.2 rotated 12t -- endfor cycle) yscaled 1/5 rotated 30);
    pickup knib;

    u := 36;

    z0 = (0,0);
    z1 = (0,1u);
    z2 = (1u,0);
    z3 = (0,-1u);
    z4 = (-1u,0);

    draw z1 -- z3 withcolor .7white;
    draw z2 -- z4 withcolor .7white;

    % switch back to the default pen
    pickup defaultpen;
    draw envelope knib of (z1--z3) withcolor red;
    draw envelope knib of (z2--z4) withcolor blue;

    dotlabels.top(0,1,2,3,4);

endfig;
end.

这产生了这个(剪辑和字体由 imagemagick 提供...):

在此处输入图片描述

这或多或少是 OP 想要的。

下一步是将返回的路径保存envelopepath变量,并用它intersectionpoint来查找它们的交叉点。您可能需要明智地使用subpath来获得所需的准确交叉点。

我正在使用 MP 2.000

toby$  mpost --v
MetaPost 2.000 (TeX Live 2017) (kpathsea version 6.2.3)
The MetaPost source code in the public domain.
MetaPost also uses code available under the
GNU Lesser General Public License (version 3 or later);
therefore MetaPost executables are covered by the LGPL.
There is NO warranty.
For more information about these matters, see the file
COPYING.LESSER or <http://gnu.org/licenses/lgpl.html>.
Original author of MetaPost: John Hobby.
Author of the CWEB MetaPost: Taco Hoekwater.
Current maintainer of MetaPost: Luigi Scarso.

Compiled with cairo 1.14.8; using 1.14.8
Compiled with pixman 0.34.0; using 0.34.0
Compiled with libpng 1.6.29; using 1.6.29
Compiled with zlib 1.2.11; using 1.2.11
Compiled with mpfr 3.1.5; using 3.1.5
Compiled with gmp 6.1.2; using 6.1.2

相关内容