Java 铸造θ(角度)浮动对数量有什么影响?
在android studio中,我一直在努力使一些图像视图旋转并面向特定坐标。使用atan2,我已将imageview的旋转设置为此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((浮动
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()
的返回值以弧度而不是度为单位。