crertel / graphmath

An Elixir library for performing 2D and 3D mathematics.
The Unlicense
81 stars 13 forks source link

Vec2 rotate CCW is slightly wrong I think #8

Closed matthewphilyaw closed 8 years ago

matthewphilyaw commented 8 years ago

Vec2d.rotate here I believe is slightly off.

I believe it should be this for CCW, but I'm not 100% sure according to this here.

def rotate( a, theta) do
  { x,y } = a
   ct = :math.cos(theta)
   st = :math.sin(theta)
  { x*ct - y*st, x*st + y*ct } # this line changed
end

The issue I'm having is that Graphmath.rotate({0,1}, :math.pi) produces {0,1} instead of {0,-1}.

Reviewing the tests, I noticed there is no case for testing the y axis, so adding something like this

@tag :vec2
@tag :rotate
test "rotate( {0,1}, :math.pi) returns {0,-1}" do
  {x,y} = Graphmath.Vec2.rotate( {0,1}, :math.pi)
  assert {0,-1} == { Float.round(x,6), Float.round(y,6)}
end

should fail. I can issue a PR for it, tomorrow just noting it. Again maybe completely wrong, not exactly the strongest in math.

crertel commented 8 years ago

This is addrssed in PR #9

crertel commented 8 years ago

PR #9 fixed this. :)