7

Let's say I have a path that represents the inside dimensions of a room. I would like to draw a thin line representing that inside space. But I would also like to draw the thickness of the walls. The naive way would be to do this where I manually add and subtract the thickness of wall assuming the pen draws on both sides of the path (that is why I have to divide the thickness by 2).

ft = 1cm;
wall_depth = 0.5ft;

% Draw the measured room outline pickup pensquare scaled 1bp; draw (0,0)--(26ft,0)--(26ft,27.5ft)--(0,27.5ft)--cycle;

% Draw in the thickness of the walls pickup pensquare scaled 0.5ft; t = wall_depth / 2; draw (0-t,0-t)--(26ft+t,0-t)--(26ft+t,27.5ft+t)--(0-t,27.5ft+t)--cycle withcolor .8 white;

enter image description here

It seems like I should be able to define a pen that only draws on the right side of the path allowing me to force the thickness to the outside of the path. Can I do this?

Alternatively I would love to be able to just tell Metapost to magically add a thick wall on the outside of my thin polygon, but I'm assuming that I can't do that.

guidoism
  • 279

1 Answers1

5

Something like this (a bit like Andrew is suggesting) could be one way, but it depends a bit on what you really want. The construction is just to get a random polygon (that might be MetaFun, but you have your path).

The top example (first image) draws the path in yellow with a wide pen, and then fills the path with blue (with transparency, to see the overlap).

The bottom example is the one with drawing to the right. First we draw the path in darkred, then we unfill the path (that is the important thing to do, but require closed paths, as you seem to have). Then we also draw the path in darkblue, just to show that what is left of the darkred drawn path is to the right.

I use ConTeXT, so the code below is a complete ConTeXt document (can be run with context). But the important MetaPost code is the same...

\startMPpage[offset=1dk]
u:=1in ;

path p ; p := unspiked circularpath(3) randomized 0.3 scaled u ;

draw image( draw p withpen pencircle scaled 2mm withcolor yellow ; fill p withcolor blue withtransparency(2,0.5) ; ) ;

draw image( draw p withpen pencircle scaled 2mm withcolor darkred ; unfill p ; draw p withcolor darkblue ; ) xshifted 1.5u ;

\stopMPpage

draw to right of path

mickep
  • 8,685
  • Oh yeah! Not sure what I was thinking but I forgot that the fill would be from the path on in, rather than the stroke on in. Yes indeed these are all going to be closed paths (until I unfill the places where the doors go) – guidoism Jan 12 '23 at 19:30
  • If you wanted sharp corners on the outer path, try adding linejoin := 0; before drawing it. – Thruston Jan 12 '23 at 19:40
  • Yes, even withlinejoin mitered works here, but maybe that is not official. – mickep Jan 12 '23 at 20:05