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:
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 ) \;.$$