Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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 铸造θ(角度)浮动对数量有什么影响?_Java_Android - Fatal编程技术网

Java 铸造θ(角度)浮动对数量有什么影响?

Java 铸造θ(角度)浮动对数量有什么影响?,java,android,Java,Android,在android studio中,我一直在努力使一些图像视图旋转并面向特定坐标。使用atan2,我已将imageview的旋转设置为此 imageview.setRotation((float) atan2(imageview.getY()-<coordinate y wanted to face>, imageview.getX()-<coordinate x wanted to face>) ); imageview.setRotation((浮动

在android studio中,我一直在努力使一些图像视图旋转并面向特定坐标。使用atan2,我已将imageview的旋转设置为此

imageview.setRotation((float) 

atan2(imageview.getY()-<coordinate y wanted to face>,
      imageview.getX()-<coordinate x wanted to face>)

);
imageview.setRotation((浮动)
atan2(imageview.getY()-,
imageview.getX()-)
);
我注意到,每次我运行这行代码时,它的方向都是相同的。(它在可绘制资源中的方向,是的,运行它的方法实际上是有效的)

那么,将atan2(θ结果)的结果转换为float是否会导致它失去其值或其他什么呢

我知道如果有必要,我可以使用matrix,但我正在试验更高效的代码


编辑:atan2以弧度返回…(1弧度=57.3度)

atan2()的返回值以弧度为单位,而
setRotation()的参数应以度为单位

你应该换成

imageView.setRotation((float)Math.toDegrees(atan2(..., ...)));

atan2()
的返回值以弧度为单位,而
setRotation()
采用的参数应以度为单位

你应该换成

imageView.setRotation((float)Math.toDegrees(atan2(..., ...)));

请注意,
atan2()
的返回值以弧度而不是度为单位。请注意,
atan2()
的返回值以弧度而不是度为单位。