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.
精彩评论