@blinkk/degu
    Preparing search index...

    Function calculate2dPointRotation

    • Use rotational matrix to calculate the new coordinates of a rotated point.

      Put another way, given point x and y, and a center point of cx and cy, calculates the translated x, y points when rotated at a given angle.

      For example:

       0,0--------------4,0
        |               |
        |       2,2     |
        |               |
       0,4 ------------ 4,4
      

      Say for example you have a rectangle. The rotational center of the rectangle is the center in this case at 2,2.

      You can use this algo to calculate rotation. Lets say you rotate the rectangle by 1 radian (~57 degrees). What is the new coordinates of the top right corner?

      const newCoords = mathf.calculate2dPointRotation(2,2,4,0,1);

      newCoords.x; // 1.398
      newCoords.y; // -0.764

      Troubleshoot?

      The most common issue is that your rotation value is inverted. Try passing in -rotation and see if that helps.

      https://www.youtube.com/watch?v=xsN8cD6oisY&feature=youtu.be https://www.youtube.com/watch?v=a59YQ4qe7mE https://en.wikipedia.org/wiki/Rotation_matrix

      Parameters

      • cx: number

        The x center point to rotate around.

      • cy: number

        The y center point to rotate around.

      • x: number

        The x value of the point to be rotated prior to rotation.

      • y: number

        The y value of the point to be rotated prior to rotation.

      • angle: number

        The angle in radians

      Returns { x: number; y: number }