Use this formula for pixel movement, they told me. It will work, they told me. Yep, no.
After all, it makes totally sense why this can not work, but later more.
fun rotateCoordinate(point: Coordinate, center: Coordinate, angleDegrees: Double): Coordinate { val angleRadians = toRadians(angleDegrees) val dx = point.x – center.x val dy = point.y – center.y val rotatedX = dx * cos(angleRadians) – dy * sin(angleRadians) val rotatedY = dx * sin(angleRadians) + dy * cos(angleRadians) return Coordinate(center.x + rotatedX, center.y + rotatedY) }
This is probably the wrong formula for the task, but for now, I just want to write down my notes.
However, after it just looked horrible in my game, I started to make it more easily visible. What we developers do in such cases—yes, we write some more code. And this is the result.
On the left side, I took the pixel coordinate of the previously rotated point and rotated it by angle 1.0.
On the right side, I took the start coordinate and rotated it by the full range.
So, whereas the rotation on the left side is, e.g., from degree 53 to 54, on the right side it is from 0 to 54.
So, what is happening here? With every rotation, the rotated point must be aligned to the coordinate system; therefore, it loses precision. It is now located somewhere else than it should be and will land somewhere else due to the next calculation, which also loses some precision. But keeping the starting point and calculating the full angle solves the issue.
But still—it could be that I am using the wrong formula, so I will continue researching it.