计算的android三个点之间的夹角夹角、android

由网友(叫我美女就扶你)分享简介:我听不太懂这有什么错我的code。 I have trouble understanding what's wrong with my code. Point A = new Point((int)CENTER_X, (int)CENTER_Y);Point B = new Point((int)me.getX(...

我听不太懂这有什么错我的code。

I have trouble understanding what's wrong with my code.

Point A = new Point((int)CENTER_X, (int)CENTER_Y);
Point B = new Point((int)me.getX(), (int)me.getY());
Point C = new Point((int)CENTER_X, (int)B.y);
double AB;
double AC;
double BC;
AB = Math.sqrt(Math.pow(B.x - A.x, 2) + Math.pow(B.y - A.y, 2));
AC = Math.sqrt(Math.pow(C.x - A.x, 2) + Math.pow(C.y - A.y, 2));
BC = Math.sqrt(Math.pow(C.x - B.x, 2) + Math.pow(C.y - B.y, 2));
degre = (AB * AB - AC * AC - BC * BC) /( 2 * AC * AB);
degre = Math.acos(degre*(180/Math.PI));

我一直让 degre = 0 NaN的。这是为什么?

推荐答案

您感到困惑的时候做的弧度度转换,你需要计算的比值,然后做的 ARCCOS (这将返回弧度角),然后将转换为像这样度:

You are confused about when to do the radian to degree translation, you need to calculate the ratio, then do the arccos (which will return an angle in radians), then convert to degrees like so:

double float ratio = (AB * AB + AC * AC - BC * BC) /( 2 * AC * AB);
degre = Math.acos(ratio)*(180/Math.PI);
阅读全文

相关推荐

最新文章