65,184
社区成员




double DrawEditSrv::getRotateAngle(const QPointF ¢erP, const QPointF &startP, const QPointF &endP)
{
double doA = sqrt((startP.x() - centerP.x())*(startP.x() - centerP.x()) + (startP.y() - centerP.y())*(startP.y() - centerP.y()));
double doB = sqrt((endP.x() - centerP.x())*(endP.x() - centerP.x()) + (endP.y() - centerP.y())*(endP.y() - centerP.y()));
double dAB = sqrt((startP.x() - endP.x())*(startP.x() - endP.x()) + (startP.y() - endP.y())*(startP.y() - endP.y()));
//角度(弧度值) cos0 = (0B^2 + OA^2 - AB^2)/(2 * 0B * OA)
double angle = acos((doB*doB + doA*doA - dAB*dAB) / (2 * doB*doA));// 正值为顺时针
//判断旋转顺逆时针
double angleA = acos((doA*doA + (startP.x() - centerP.x())*(startP.x() - centerP.x()) - (startP.y() - centerP.y())*(startP.y() - centerP.y())) / (2 * doA*(startP.x() - centerP.x())));
double angleB = acos((doB*doB + (endP.x() - centerP.x())*(endP.x() - centerP.x()) - (endP.y() - centerP.y())*(endP.y() - centerP.y())) / (2 * doA*(endP.x() - centerP.x())));
//判断项象 (注:T面 Y坐标从上到下递减)
if (startP.y() < centerP.y() && endP.y() < centerP.y())
{
//AB点都在第一二项象
if (angleB > angleA)
angle = -angle;
}
else if (startP.y() > centerP.y() && endP.y() > centerP.y())
{
//AB点都在第三四项象
if (angleA > angleB)
angle = -angle;
}
else if ((startP.x() > centerP.x() && startP.y() > centerP.y()) && (endP.x() > centerP.x() && endP.y() < centerP.y()))//A在四,B在一,逆
angle = -angle;
else if ((startP.x() < centerP.x() && startP.y() < centerP.y()) && (endP.x() < centerP.x() && endP.y() > centerP.y()))//A在二,B在三,逆
angle = -angle;
return angle;
}