Here image rotation from the standpoint of point rotations, might be easier to understand?
Edit: fixed error in the 2 _MapTriangle lines.
Code: (Select All)
_Title "Rotate Point" 'b+ 2022-09-08
Screen _NewImage(800, 600, 32)
rotateCenterX = _Width / 2
rotateCenterY = _Height / 2
' test rotate point about the middle of the screen start point at 300, 100 and rotate 1/12 circle = 30 degree or pi/12 radians
x = 300: y = 100
Circle (x, y), 1, &HFF0000FF
For a = _Pi(2 / 12) To _Pi(2 - 1 / 6) Step _Pi(1 / 6)
Cls
Print "rotated"; _R2D(a); " degrees, press any to continue demo"
Circle (x, y), 1, &HFF0000FF
drawRotate x, y, rotateCenterX, rotateCenterY, a
Sleep
Next
' OK make a rectangle image 50x100
Line (0, 0)-(49, 99), &HFFFFFF00, BF
rect& = _NewImage(50, 100, 32)
_PutImage , 0, rect&, (0, 0)-(49, 99)
_PutImage (_Width - _Width(rect&), 0), rect&, 0
_PutImage (0, _Height - _Height(rect&)), rect&, 0
_PutImage (_Width - _Width(rect&), _Height - _Height(rect&)), rect&, 0
For a = 0 To _Pi(2) - .001 Step _Pi(1 / 6)
Cls
rotateImage rotateCenterX, rotateCenterY, rect&, a, 0
Print "Rotated"; _R2D(a)
Sleep
Next
Sub rotateImage (aboutX, aboutY, Img&, radianRot, dest&)
Dim px(1 To 4), py(1 To 4), rotx(1 To 4), roty(1 To 4)
w = _Width(Img&) / 2 ' these are 1/2 widths and heights for faster calc
h = _Height(Img&) / 2
px(1) = aboutX - w: py(1) = aboutY - h
px(2) = aboutX - w: py(2) = aboutY + h
px(3) = aboutX + w: py(3) = aboutY + h
px(4) = aboutX + w: py(4) = aboutY - h
For i = 1 To 4
Rotate px(i), py(i), aboutX, aboutY, radianRot, rotx(i), roty(i)
Next
w = _Width(Img&) - 1 'for source coordinates
h = _Height(Img&) - 1
_MapTriangle (0, 0)-(0, h)-(w, h), Img& To(rotx(1), roty(1))-(rotx(2), roty(2))-(rotx(3), roty(3)), dest&
_MapTriangle (0, 0)-(w, 0)-(w, h), Img& To(rotx(1), roty(1))-(rotx(4), roty(4))-(rotx(3), roty(3)), dest&
End Sub
Sub drawRotate (x, y, aboutX, aboutY, rotRA)
radius = _Hypot(y - aboutY, x - aboutX)
angle = _Atan2(y - aboutY, x - aboutX)
rotA = angle + rotRA
'rotated x, y point
rotX = aboutX + radius * Cos(rotA)
rotY = aboutY + radius * Sin(rotA)
Circle (rotX, rotY), 1, &HFFFFFF00
End Sub
' rotate point x,y about point aboutX, aboutY, Radian Angles, (output) rotX, (output) rotY
Sub Rotate (x, y, aboutX, aboutY, rotRA, rotX, rotY)
radius = _Hypot(y - aboutY, x - aboutX)
angle = _Atan2(y - aboutY, x - aboutX)
rotA = angle + rotRA
'rotated x, y point
rotX = aboutX + radius * Cos(rotA)
rotY = aboutY + radius * Sin(rotA)
End Sub
Edit: fixed error in the 2 _MapTriangle lines.
b = b + ...