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,
const QPointF &secondPoint)
{
QPointF pArc;
qreal s = 0.0, s_x, s_y, step = 0.01, distans;
while ( s < 1)
QPointF p1, p2;
qint32 res = LineIntersectCircle(center, radius, QLineF(firstPoint, secondPoint), p1, p2);
switch (res)
{
s_x = secondPoint.x()-(qAbs(secondPoint.x()-firstPoint.x()))*s;
s_y = secondPoint.y()-(qAbs(secondPoint.y()-firstPoint.y()))*s;
distans = QLineF(center.x(), center.y(), s_x, s_y).length();
if (fabs(distans*10 - radius*10) < 0.1)
{
pArc.rx() = s_x;
pArc.ry() = s_y;
case 0:
return QPointF();
break;
case 1:
return p1;
break;
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;
}
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
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();
// add to projection a vectors aimed to points of intersection
p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t);