Search code examples
geometrypointvector-graphics

Rotate array of points according one point


I have 4 points and angle (as shown on the picture). How to get new point values for rotated object?

picture(x/y axis inverted, mistake. Vertical should be Y, horizontal - X)


Solution

  • At first, get coordinates relative to the rotation origin (x0, y0)

    x' = x1 - x0
    y' = y1 - y0
    

    Then rotate

    x'' = x' * Cos(Fi) - y' * Sin(Fi)
    y'' = x' * Sin(Fi) + y' * Cos(Fi)
    

    And now shift coordinates back

    x_r = x'' + x0
    y_r = y'' + y0