I have to draw a regular shape, that fits inside a rectangle of given size. The pen used to draw that shape follows the shape I say it is - going from corner to corner - but the pen thickness is centered on contour.

If I draw the shape as given, because half of the pen is outside the box, corners stick outside the box - I get smears.

I have been struggling to find a formula, based on angles and sizes, but nothing works...

Simplest case: equilateral triangle - start coordinates, P0(50,0); P1(0,87); P2(100,87) (or (100*cos60,0); (0,100*sin60); (100,100*sin60))

Some odd situations - I am trying to adjust the corners so my triangle fits entirely in its bounding rectangle, but obviously not with much success:

enter image description here

I am trying to find a formula involving w, h, the shape angle (60 in this case), and pen thickness, to find the coordinates to place the triangle corners so that its entire shape will fit. (Possibly limiting the pen thickness based on w and h as well, right now I have it limited to min(thickness, w/2, h/2)).

Would it also be possible to find a similar formula for a right triangle ?


This may help:

$$x = y / \tan( \theta/2 ) \;.$$

  • $\begingroup$ So that is something like x=y/tan(arctan(2h/w)/2) right ? Thanks I will try to figure out a similar formula for the top shift $\endgroup$ – Thalia Oct 15 '15 at 13:26
  • $\begingroup$ The top then may be `y/cos(theta)' I think $\endgroup$ – Thalia Oct 15 '15 at 13:40
  • $\begingroup$ @Thalia: The extra side length $x$ is dependent on the offset $y$ and the angle $\theta$ at the corner. I drew an isosceles triangle so that two of its three angles are the same, but in general you would need to make an analogous computation for each corner. $\endgroup$ – Joseph O'Rourke Oct 15 '15 at 14:31

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.