1

In Metapost, I want to copy a path and be able to address the points directly. I tried this, but it seems like pp1 doesn not exists. Any idea how to do it?

beginfig(1);
    pair p[];
    p1=(0,100);
    p2=(50, 0);
    p3=(100,100);

    pair pp[];
    pp := p shifted (25, 0);

    show p[1];
    show pp[1];

    draw p[1] -- pp[1];
endfig;
3

p is not a path, it is an array. You have to iterate over all the suffixes and shift them:

beginfig(1);
    pair p[];
    p1=(0,100);
    p2=(50, 0);
    p3=(100,100);

    pair pp[];

    forsuffixes i = 1,2,3  :
      pp[i] := p[i] shifted (25, 0);
    endfor

    show p[1];
    show pp[1];

    draw p[1] -- pp[1];
endfig;
end;

The other option is to actually define a path and then access individual points using point n of path:

beginfig(1);
  path p, pp;

  p := (0,100) -- (50,0) -- (100,100);
  pp := p shifted (25, 0);

  show point 0 of p;
  show point 0 of pp

  draw point 0 of p -- point 0 of pp;
endfig;
end;
  • Technically pair p[] does not really define an array either; it's more a collection of variables with a common prefix. So, for example, you are not limited to using integers as suffixes: after pair p[], you could use p.A, p.2r, etc as well as p1... – Thruston Jan 25 '18 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.