matrix ã©ã¤ãã©ãªã¼ã®ä½¿ãæ¹
question:1191841779
matrix ライブラリーã®ä½¿ãæ¹ãå°ãããã£ãã®ã§ãããã使ã£ã¦æ¸ãç´ãã¦ã¿ãã
require 'matrix' class Vector2 < Vector DIMENSION = 2 def self.[](*array) self.Raise ErrDimensionMismatch if array.size != DIMENSION super end def self.elements(array, copy = true) self.Raise ErrDimensionMismatch if array.size != DIMENSION super end def rotate(angle) cos = Math.cos(angle) sin = Math.sin(angle) mat = Matrix[[cos, -sin], [sin, cos]] mat * self # .class == Vector...orz end end x = 13.0 y = 6.0 angle_degree = 47.0 angle = angle_degree * Math::PI / 180.0 # convert degrees into radians p Vector2[x, y].rotate(angle) # => Vector[4.47785647109746, 13.5995882814242] p Vector2.elements([x, y]).rotate(angle)# => Vector[4.47785647109746, 13.5995882814242]
復帰å¤ã Vector ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã«ãªã£ã¦ãã¾ãã®ãçã(ï¾â`)â¦â¦*1
*1:ã¯ã©ã¹åã決ãæã¡ã«ããã®ã¯æ¢ãã¦æ¬²ããã