# [metapost] Feature Request: Get envelope of path stroked with arbitrary pen

luigi scarso luigi.scarso at gmail.com
Fri Feb 9 12:28:10 CET 2018

```On Fri, Feb 9, 2018 at 4:36 AM, Kevin Keith <krfkeith at gmail.com> wrote:
>> Among other issues, the envelope of a path defined by cubic splines is not
>> itself a cubic spline, so you need to do some approximation, and coming up
>> with rules for how close the approximation needs to be, that cover all
>> cases,
>> is difficult.
>
> Of course, but how does Metapost output pen strokes to eps or svg as it is?
> Surely
> it must already have a mechanism to approximate these higher-order splines
> with
> cubic bezier curves?
>
>> I can think about it, but first I need a small set of significant
>> examples (quite unlikely that I will implement something new for the
>> next texlive,  btw) .
>
> I'll give you the main issue I've run into: say I'm trying to design a font
> which
> is composed of pen strokes, but I want them to be joined smoothly. This is a
> rather
> contrived example, but I've put together an illustration of what I mean:
> https://i.stack.imgur.com/pzy8e.png
>
envelope of a cubic spline is tricky
and Metafont makes a polygonal approximation of the elliptical pen
(ie a linearization of the problem).
Metapost has the envelope instruction that works with
polygonal pen;
one can make an approximation of  a pen and  with the availability of
several numbersystem
the precision is not more a problem.

beginfig(1);
path p[] ;
pen mypen ;
pen mypenC;
numeric L ;
numeric S ;
L:=10;
Sa:=1;
Sb:=2;
Rot=32;
p[-1] := ( (Sa*cosd(0),Sb*sind(0)) for i=1 upto L-1: --
(Sa*cosd(i/L*360), Sb*sind(i/L*360)) endfor -- cycle )  rotated Rot;
mypen := makepen(p[-1]) ;
mypenC:= (pencircle xscaled 2Sa yscaled 2Sb) rotated Rot;
p0 := (0,0){down} .. {up} (100,0)  ;
p1 := envelope  mypen  of p0 ;
message "length p1=" & decimal(length(p1));
draw  p1 withcolor blue   withpen pencircle scaled 0.25pt ;

draw p0 withcolor 0.8white withpen mypenC;

for t=1 upto length(p1):
draw (point t of p1) withcolor red withpen pencircle scaled 0.3pt;
endfor;

currentpicture := currentpicture scaled  10 ;
endfig;
end

--
luigi
```