Sha256: 8c257c58fada5b37140e7e6234a48bbffbebc824800b9e5c8213ad51b30368e6

Contents?: true

Size: 513 Bytes

Versions: 13

Compression:

Stored size: 513 Bytes

Contents

module GridGenerator
  class Rotator
    def initialize(angle:, rotation_point:)
      @angle = angle 
      @matrix = Matrix[
        [Math.cos(angle), -1*Math.sin(angle)],
        [Math.sin(angle), Math.cos(angle)]
      ]
      @rotation_point = rotation_point
    end

    attr_reader :angle, :matrix, :rotation_point

    def rotate(point) 
      # subtract rotation point to move point towards 0,0, rotate, then add to move back
      (matrix * (point - rotation_point)) + rotation_point 
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
grid_generator-0.2.10 lib/grid_generator/rotator.rb
grid_generator-0.2.9 lib/grid_generator/rotator.rb
grid_generator-0.2.8 lib/grid_generator/rotator.rb
grid_generator-0.2.7 lib/grid_generator/rotator.rb
grid_generator-0.2.6 lib/grid_generator/rotator.rb
grid_generator-0.2.5 lib/grid_generator/rotator.rb
grid_generator-0.2.4 lib/grid_generator/rotator.rb
grid_generator-0.2.3 lib/grid_generator/rotator.rb
grid_generator-0.2.2 lib/grid_generator/rotator.rb
grid_generator-0.2.1 lib/grid_generator/rotator.rb
grid_generator-0.2.0 lib/grid_generator/rotator.rb
grid_generator-0.1.12 lib/grid_generator/rotator.rb
grid_generator-0.1.11 lib/grid_generator/rotator.rb