Created
October 11, 2011 16:47
-
-
Save sugamasao/1278649 to your computer and use it in GitHub Desktop.
座標変換のつもり
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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