Rotation in a Vector2d class in Java
Posted
by
wanstein
on Stack Overflow
See other posts from Stack Overflow
or by wanstein
Published on 2011-03-06T00:08:45Z
Indexed on
2011/03/06
0:10 UTC
Read the original article
Hit count: 152
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
© Stack Overflow or respective owner