Skip to content

Instantly share code, notes, and snippets.

@hugabor
Created January 5, 2021 03:25
Show Gist options
  • Save hugabor/b17c1ff71f63ceba467c1f8a98a298fa to your computer and use it in GitHub Desktop.
Save hugabor/b17c1ff71f63ceba467c1f8a98a298fa to your computer and use it in GitHub Desktop.

Default rotation matrix multiply:

(x', y')^T = ((cosθ, -sinθ), (sinθ, cosθ)) * (x, y)^T

(multiplied out)

  • x' = x cosθ - y sinθ
  • y' = x sinθ + y cosθ

Rotation formula around center point:

(translate)

  • xT = x - cx
  • yT = y - cy

(untranslate)

  • x" = xT' + cx
  • y" = yT' + cy

(rotate + untranslate)

  • x" = xT cosθ - yT sinθ + cx
  • y" = xT sinθ + yT cosθ + cy

(translate + rotate + untranslate)

  • x" = (x - cx) cosθ - (y - cy) sinθ + cx
  • y" = (x - cx) sinθ + (y - cy) cosθ + cy

(expanded)

  • x" = x cosθ - cx cosθ - y sinθ + cy sinθ + cx
  • y" = x sinθ - cx sinθ + y cosθ - cy cosθ + cy

With particular parameters:

  • θ = PI/2
  • cx = cy = 0

-->

  • x" = x (0) - (0) (0) - y (1) + (0) (1) + (0)
  • y" = x (1) - (0) (1) + y (0) - (0) (0) + (0)

-->

  • x" = -y
  • y" = x

  • θ = PI
  • cx = cy = 0

-->

  • x" = x (-1) - (0) (-1) - y (0) + (0) (0) + (0)
  • y" = x (0) - (0) (0) + y (-1) - (0) (-1) + (0)

-->

  • x" = -x
  • y" = -y

  • θ = PI/2
  • cx = cy = c

-->

  • x" = x (0) - c (0) - y (1) + c (1) + c
  • y" = x (1) - c (1) + y (0) - c (0) + c

-->

  • x" = -y + 2c
  • y" = x

  • θ = PI
  • cx = cy = c

-->

  • x" = x (-1) - c (-1) - y (0) + c (0) + c
  • y" = x (0) - c (0) + y (-1) - c (-1) + c

-->

  • x" = -x + 2c
  • y" = -y + 2c

  • θ = 3 PI / 2
  • cx = cy = c

-->

  • x" = x (0) - c (0) - y (-1) + c (-1) + c
  • y" = x (-1) - c (-1) + y (0) - c (0) + c

-->

  • x" = y
  • y" = -x + 2c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment