New way to find point intersection of an arc with a segment.

--HG--
branch : develop
This commit is contained in:
dismine 2014-10-18 20:56:25 +03:00
parent 769219f9b8
commit 07ea6c6de5
2 changed files with 23 additions and 19 deletions

View File

@ -95,27 +95,31 @@ void VToolPointOfContact::setDialog()
QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF &center, const QPointF &firstPoint, QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF &center, const QPointF &firstPoint,
const QPointF &secondPoint) const QPointF &secondPoint)
{ {
QPointF pArc; QPointF p1, p2;
qreal s = 0.0, s_x, s_y, step = 0.01, distans; qint32 res = LineIntersectCircle(center, radius, QLineF(firstPoint, secondPoint), p1, p2);
while ( s < 1) switch (res)
{ {
s_x = secondPoint.x()-(qAbs(secondPoint.x()-firstPoint.x()))*s; case 0:
s_y = secondPoint.y()-(qAbs(secondPoint.y()-firstPoint.y()))*s; return QPointF();
distans = QLineF(center.x(), center.y(), s_x, s_y).length(); break;
if (fabs(distans*10 - radius*10) < 0.1) case 1:
{ return p1;
pArc.rx() = s_x; break;
pArc.ry() = s_y; case 2:
if (QLineF(firstPoint, p1).length() <= QLineF(firstPoint, p2).length())
{
return p1;
}
else
{
return p2;
}
break;
default:
qDebug() << "Unxpected value" << res;
return QPointF();
break; break;
}
if (distans<radius)
{
pArc.rx() = s_x;
pArc.ry() = s_y;
}
s = s + step;
} }
return pArc;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -206,7 +206,7 @@ qint32 VAbstractTool::LineIntersectCircle(const QPointF &center, qreal radius, c
} }
} }
// find distance from projection to points of intersection // find distance from projection to points of intersection
qreal k = qSqrt (radius * radius - d * d); qreal k = qSqrt (qAbs(radius * radius - d * d));
qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length();
// add to projection a vectors aimed to points of intersection // add to projection a vectors aimed to points of intersection
p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t); p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t);