计算的android三个点之间的夹角 [英] Calculating the angle between three points in android

查看:879
本文介绍了计算的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(), (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);

这篇关于计算的android三个点之间的夹角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆