0
How do we create a rectangle that is tilted.
5 Respostas
+ 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
+ 1
And thanks Seb TheS, haha, i'm 8th grader so i'll likely not be able to understand.
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.
0
Daniel C, does this... rotate the canvas, or only the rectangle?
0
My code will only rotate the rectangle, not the canvas.