I have two neighboring (complicated) polygons that I want to be displayed with thick boundaries, however the two shapes border one another, and as EdgeForm places the line centered upon the polygon's boundary, the border of one shape overlaps the other. I would like the boundary lines to lie interior to the polygon's boundaries.

Here's shape 1, shape 2, and then the two shapes shown together:

enter image description here

enter image description here

enter image description here

Obviously one could just shrink the shapes by a little bit, but this is not very exact. I was thinking a clever EdgeForm definition might be able to "offset" the boundary to the shape's interior.

  • 2
    $\begingroup$ I have wanted this myself but I have never found a solution within EdgeForm itself. I too have ended up shrinking shapes to make them fit. As far as I know Mathematica lacks the "inside stroke" method that you describe. Once again I hope I am proven wrong. :-) $\endgroup$ – Mr.Wizard Aug 25 '14 at 7:40

This is probably the simplest approach, but it only works with AspectRatio -> Automatic, and the thickness seems to be constant in an $L^1$-sense rather than $L^2$.

p1 = Polygon[{{-1, 0}, {1, 0}, {0, 1}}];
p2 = Polygon[{{-1, 0}, {1, 0}, {0, -1}}];

With[{t = 0.94}, Show[Graphics[{
   {Red,   p1, White, Scale[p1, t], Red,   Opacity[1/3], Scale[p1, t]},
   {Green, p2, White, Scale[p2, t], Green, Opacity[1/3], Scale[p2, t]}}]]]

| improve this answer | |
  • $\begingroup$ With FilledCurve you can exclude regions from polygon: "Self-intersecting curves are filled according to an even-odd rule that alternates between filling and not at each crossing. FilledCurve[{component1, component2, ...}] treats each component curve as a separate closed curve, but the filling behavior is determined as if they were part of the same curve." $\endgroup$ – Alexey Popkov Feb 20 '17 at 11:46
  • $\begingroup$ An example: FilledCurve[{{Line[{{-1, -1}, {-1, 1}, {1, 1}, {1, -1}}]}, {Line[.9 {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}}]}}]. $\endgroup$ – Alexey Popkov Feb 20 '17 at 11:48
  • $\begingroup$ With Offset coordinates the shape will be independent from AspectRatio. $\endgroup$ – Alexey Popkov Feb 20 '17 at 11:50
  • $\begingroup$ While this is close, it's certainly not perfect, the difference in line thickness between the different sides can be quite noticeable: i.imgur.com/fb5U4SQ.png $\endgroup$ – Guillochon Feb 22 '17 at 0:38

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.