Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中Vector2d类中的旋转_Java_Vector_Rotation - Fatal编程技术网

Java中Vector2d类中的旋转

Java中Vector2d类中的旋转,java,vector,rotation,Java,Vector,Rotation,我已经做了一个小时了,就是搞不懂 我有一个Vector2d类: public class Vector2d { public double x = 0.0; public double y = 0.0; .... } 这个向量类有一个rotate()方法,这给我带来了麻烦 第一个片段似乎使x和y值越来越小。第二个很好用!我是不是错过了一些简单的东西 public void rotate(double n) { this.x = (this.x * Math.c

我已经做了一个小时了,就是搞不懂

我有一个Vector2d类:

public class Vector2d
{
    public double x = 0.0;
    public double y = 0.0;

    ....
}
这个向量类有一个rotate()方法,这给我带来了麻烦

第一个片段似乎使x和y值越来越小。第二个很好用!我是不是错过了一些简单的东西

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));
}
这项工作:

public void rotate(double n)
{
    double rx = (this.x * Math.cos(n)) - (this.y * Math.sin(n));
    double ry = (this.x * Math.sin(n)) + (this.y * Math.cos(n));
    x = rx;
    y = ry;
}

我就是看不出有什么不同

第一行设置了
this.x
的值,然后在第二行中使用,而您真正想要的是
this.x
的原始值。第二个版本可以正常工作,因为您不需要更改
this.x

第一行设置
this.x
的值,当您真正需要的是
this.x
的原始值时,该值将在第二行中使用。第二个版本很好用,因为你没有修改
这个.x

哦,不,真不敢相信我错过了。我觉得自己很愚蠢。非常感谢。哦,不,真不敢相信我错过了。我觉得自己很愚蠢。非常感谢。