开发者

Math In Android?

开发者 https://www.devze.com 2023-04-06 10:07 出处:网络
How can I write this in math functi开发者_运维技巧on in Android, im stuck on how to multiply things and use atan2:

How can I write this in math functi开发者_运维技巧on in Android, im stuck on how to multiply things and use atan2:

Math.atan2(posY, posX) * 180/Math.PI;


Try this,

((Math.atan2(posY, posX)) * 180)/Math.PI


You imported java.lang.Math, correct?

http://developer.android.com/reference/java/lang/Math.html


Atan2 is generally used to find the angle from one point to another. Usually the parameters are the Y-difference between the two points and the X-difference between the two points:

 double deltaX=endX-startX;
 double deltaY=endY-startY;
 double angleInDegrees=Math.atan2(deltaY,deltaX) * 180 / Math.PI;

The conversion to degrees (* 180 / Math.PI) is needed because atan2 returns radians, not degrees.

0

精彩评论

暂无评论...
验证码 换一张
取 消