Skip to content

Instantly share code, notes, and snippets.

@sugamasao
Created October 11, 2011 16:47
Show Gist options
  • Save sugamasao/1278649 to your computer and use it in GitHub Desktop.
Save sugamasao/1278649 to your computer and use it in GitHub Desktop.
座標変換のつもり
def x_rotate(x, y, r)
(x * Math.cos(r/180.0 * Math::PI)) - (y * Math.sin(r/180.0 * Math::PI))
end
def y_rotate(x, y, r)
(x * Math.sin(r/180.0 * Math::PI)) + (y * Math.cos(r/180.0 * Math::PI))
end
def rotate(x, y, r);
{:x => x_rotate(x, y, r), :y => y_rotate(x, y, r)}
end
rotate(10, 6, 60)
=> {:x=>-0.19615242270663114, :y=>11.660254037844386}
# x がマイナスになってるのが気になるんだよなー
# 参考: http://www1.ocn.ne.jp/~zodiac/misc/cg/trans.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment