I am trying to draw a Rectangle centered on a hexagon like in the attached illustration and I would like to ask for help how to achieve that.
For the drawing API I'm using I need to know:
I know:
The size of the line from the center of the hexagon to the top-left point of the rectangle should be [math]d=\frac{\sqrt{r.width^2 + r.height^2}}{2}[/math]
With the law of cosines I can get the required angle from the center of the hexagon to the rectangle's corner:
[math]angle = arccos(\frac{a^2+b^2-c^2}{2ab})[/math]
So in my case I should be able to calculate this angle with: [math]angle = arccos(\frac{2d^2-r.height^2}{4d})[/math]
And this is where I'm stuck because I am not sure if this is correct and how to calculate the location of the rectangle's top-left corner with that?
For the drawing API I'm using I need to know:
- the location of the top-left point of the rectangle
I know:
- the location of the hexagon's center
- the width and height of the rectangle
The size of the line from the center of the hexagon to the top-left point of the rectangle should be [math]d=\frac{\sqrt{r.width^2 + r.height^2}}{2}[/math]
With the law of cosines I can get the required angle from the center of the hexagon to the rectangle's corner:
[math]angle = arccos(\frac{a^2+b^2-c^2}{2ab})[/math]
So in my case I should be able to calculate this angle with: [math]angle = arccos(\frac{2d^2-r.height^2}{4d})[/math]
And this is where I'm stuck because I am not sure if this is correct and how to calculate the location of the rectangle's top-left corner with that?