0

How do we create a rectangle that is tilted.

2nd Nov 2019, 1:07 PM
Bright Lin
Bright Lin - avatar
5 Answers
+ 3
If you mean on a canvas as the tags suggest, check out the JavaScript in this code: https://code.sololearn.com/WR7Sr9O6636L/?ref=app
2nd Nov 2019, 1:55 PM
Daniel C
Daniel C - avatar
+ 1
And thanks Seb TheS, haha, i'm 8th grader so i'll likely not be able to understand.
2nd Nov 2019, 7:47 PM
Bright Lin
Bright Lin - avatar
0
Mathematically if rectangle's 4 points were (a, b), (c, d), (e, f), (g, h), rotation point was (i, j) and rotation angle was E, then new rectangle would be: Point distances from the rotation point: k = sqrt((a-i)**2 + (b-j)**2) l = sqrt((c-i)**2 + (d-j)**2) m = sqrt((e-i)**2 + (f-j)**2) n = sqrt((g-i)**2 + (h-j)**2) A = atan2(a-i, b-j) B = atan2(c-i, d-j) C = atan2(e-i, f-j) D = atan2(g-i, h-j) The final dots would be: (i + k*cos(A+E), j + k*sin(A+E)) (i + l*cos(B+E), j + l*sin(B+E)) (i + m*cos(C+E), j + m*sin(C+E)) (i + n*cos(D+E), j + n*sin(D+E)) It might complex, but it can be simplified with functions.
2nd Nov 2019, 4:37 PM
Seb TheS
Seb TheS - avatar
0
Daniel C, does this... rotate the canvas, or only the rectangle?
2nd Nov 2019, 7:46 PM
Bright Lin
Bright Lin - avatar
0
My code will only rotate the rectangle, not the canvas.
2nd Nov 2019, 8:55 PM
Daniel C
Daniel C - avatar