Geometry problem: Fit Triangle within 500px after border applied

102 Views Asked by At

I am studying drawing shapes programmatically. When I draw Triangle then the border radius is not fitting in to the container of the Layer which is used to draw the triangle shape.

Container box size:

Width: 500 Height: 500

Border width of the triangle: 100

values are in pixel

How I drew triangle programmatically by using polygon:

height = container.box.height width = container.box.width

  1. Move to point (0,0)
  2. Draw Line to the point(width/2,height/2)
  3. Draw Line to the point(width/2,0)
  4. close the polygon. So, it'll draw the opposite line automatically.

Now, We'll get two triangle. One is border, Another one is fill

My program draws triangle perfectly but, with border the triangle box size increases more than 500x500 size. But I want to fit the triangle to container.box. Please see below Gif image and screenshots you can understand What I am telling. There should be formulae to solve this problem. I need to solve this problem. Thanks in advance.

Here is the image for clear understanding:

GIF Animation:

enter image description here

Screenshot:

Screen Shot

enter image description here