Rotation in a Vector2d class in Java
- by wanstein
I've been working on this for one hour, just can't get it.
I have a Vector2d class:
public class Vector2d
{
public double x = 0.0;
public double y = 0.0;
....
}
This vector class has a rotate() method which is causing me trouble.
The first snippet seems to make the x and y values smaller and smaller. The second one works just fine! Am I missing something simple here?
public void rotate(double n)
{
this.x = (this.x * Math.cos(n)) - (this.y * Math.sin(n));
this.y = (this.x * Math.sin(n)) + (this.y * Math.cos(n));
}
This works:
public void rotate(double n)
{
rx = (this.x * Math.cos(n)) - (this.y * Math.sin(n));
ry = (this.x * Math.sin(n)) + (this.y * Math.cos(n));
x = rx;
y = ry;
}
I just can't spot any difference there