-1

I am having trouble with finding the X and Y-coordinates of the center of a rotated rectangle through mathematical calculations. What I have is the width 'A' and height 'B' of a rectangle, as well as its rotation 'R' in degrees. What would be the formula to calculate those points? Here is a sketch to further explain what i am trying to do: enter image description here

Any help is greatly appreciated! :)

  • Depends on how you are rotating the `
    `? ``? This is JavaScript...and there's more than one way to *"skin a cat"*. CSS as well.
    – zer00ne Aug 04 '22 at 09:51
  • Oh, forgot to mention, I am only interested in the mathematical formula, not anything jsvascript related. Added the javascript tag by mistake.. – LaurenzMorbe Aug 04 '22 at 09:56
  • Your question is quite confuse. On one hand you ask for the coordinates of the center of the rectangle (most probably the rotation center, so it does not move), and on the other you want to calculate "those points" !? –  Aug 05 '22 at 08:22
  • And if all you know is A, B, R, it is completely impossible to find the rectangle position. –  Aug 05 '22 at 08:25
  • @YvesDaoust I also know the coordinates of the left-uppermost corner of the square, forgot to mention that sorry – LaurenzMorbe Aug 05 '22 at 19:49
  • What is the left-uppermost ?? There is a leftmost and an uppermost, and they differ. –  Aug 06 '22 at 10:29
  • In the case shown by the picture, it is the leftmost point I have the coords of. It is always that point/corner of which i have the coordinates, it doesnt change. Maybe I didnt describe that well. – LaurenzMorbe Aug 07 '22 at 10:48

2 Answers2

0

if you are trying to do it in pure way, by your self it think this answer would be great for you https://math.stackexchange.com/questions/270194/how-to-find-the-vertices-angle-after-rotation

if you want to use a package for this, then I do recommend flatten-js , geometric ,Ecluid.ts

  • Thanks, but the issue is that the link you provided does the opposite: Calculate the corner points with the rotation of the center one. I am trying to achieve the opposite. – LaurenzMorbe Aug 04 '22 at 10:12
  • in the accepted answer, there is an explanation of how to find any point, not only the corner – Tareq Alsayed Aug 04 '22 at 10:18
  • for your situation, the center point is (a/2 + dx, b/2 +dy) "before rotate", so with the accepted answer you could calculate it after the rotation in respect of other point with a specific angle – Tareq Alsayed Aug 04 '22 at 10:20
0

I doubt that this is what you are after, but here is a solution to a possibly related question.

We assume that the leftmost corner lies on the Y axis, and the bottommost on the X axis. Thus, the coordinates of these corners are (0, B sin R) and (B cos R, 0) respectively. The midpoint of the bottom side is (B/2 cos R, B/2 sin R). To this we add a vector of length A/2 in the orthogonal direction and obtain the coordinates of the center:

(B/2 cos R - A/2 sin R, B/2 sin R + A/2 cos R)