Skip to content

Instantly share code, notes, and snippets.

@danfinnie
Created March 8, 2014 03:42
Show Gist options
  • Save danfinnie/9424998 to your computer and use it in GitHub Desktop.
Save danfinnie/9424998 to your computer and use it in GitHub Desktop.
Rotation Matrix
def cos *args
Math.cos(*args)
end
def sin *args
Math.sin(*args)
end
def funky_func(theta)
proc do |x, y|
[cos(theta) * x + -1 * sin(theta) * y, sin(theta) * x + cos(theta) * y]
end
end
describe "math and stuff" do
let(:theta) { rand * Math::PI / 2 }
it "rotates into the first quadrant" do
x, y = funky_func(theta).(1, 0)
expect(x).to be_within(0.01).of(cos(theta))
expect(y).to be_within(0.01).of(sin(theta))
end
it "rotates into the second quadrant" do
x, y = funky_func(theta).(0, 1)
expect(x).to be_within(0.01).of(-1 * sin(theta))
expect(y).to be_within(0.01).of(cos(theta))
end
it "does other stuff" do
x, y = funky_func(Math::PI/2).(0.5, 0.5)
expect(x).to be_within(0.01).of(-0.5)
expect(y).to be_within(0.01).of(0.5)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment