我正在尝试从基于象限的点计算角度,但是对于某些象限,我得到了奇怪的值,这导致我的操作不完整。
基本上我需要知道的是具有中心点(x1,y1)的对象的角度。从具有中心点 (x2, y2) 的第二个对象开始,该中心点被认为是象限的中心。x2, y2 永远不会是 0,0。因为它在屏幕的某个位置。
所以,我正在执行以下代码:
int y = point.center().y - quadrant.center().y;
int x = point.center().x - quadrant.center().x;
float angle = std::atan2(y, x) * 180/acos(-1);
//this was my try to fix the strange values that the code above is giving, but no sucess
float angle = std::atan2(y < 0 ? -y : y, x < 0 ? -x : x) * * 180/acos(-1);
我得到以下奇怪的输出,这些输出与我在获得确切角度后要做的事情有关。
你们能告诉我这里有什么问题吗?
编辑:
int y = point.center().y - source.rect.center().y;
int x = point.center().x - source.rect.center().x;
float angle = std::atan2(y, x) * RAD_TO_DEC;
Point ponta;
Point raio = Point(source.rect.bottomRight().x - source.center.x, source.rect.bottomCenter().y - source.center.y);
if (angle >= 0.0f && angle <= 90.0f) {
//right bottom
ponta = point.bottomRight();
raio = Point(source.rect.bottomRight().x, source.rect.bottomCenter().y);
g_logger.info(stdext::format("Radius: y%d x%d, ponta x%d %y, x%d y%d - angulo: %f", raio.x ,raio.y, ponta.x, ponta.y, x, y, angle));
if (ponta.x <= raio.x && ponta.y <= raio.y && ponta.x) {
return true;
}
}