Added FindF2 in VEllipticalArc

--HG--
branch : feature
This commit is contained in:
Valentina Zhuravska 2016-02-24 17:34:03 +02:00
parent e1837d1b03
commit 06637f2103
2 changed files with 47 additions and 9 deletions

View File

@ -361,7 +361,44 @@ void VEllipticalArc::EllipticalArcName()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VEllipticalArc::FindF2(qreal length) void VEllipticalArc::FindF2(qreal length)
{ {
// We need to calculate the second angle, qreal gap = 180;
if (length < 0)
{
//length = qAbs(length);
d->isFlipped = true;
gap = -gap;
}
while (length > MaxLength())
{
//length = length - MaxLength();
}
// We need to calculate the second angle
// first approximation of angle between start and end angles
qreal endAngle = GetStartAngle() + gap;
d->f2 = endAngle; // we need to set the end anngle, because we want to use GetLength()
qreal lenBez = GetLength(); // first approximation of length
qreal eps = 0.001 * qAbs(length);
while (qAbs(lenBez - length) > eps)
{
gap = gap/2;
if (lenBez > length)
{ // we selected too big end angle
endAngle = endAngle - qAbs(gap);
}
else
{ // we selected too little end angle
endAngle = endAngle + qAbs(gap);
}
d->f2 = endAngle;
lenBez = GetLength();
}
d->formulaF2 = QString("%1").arg(d->f2);
d->formulaLength = QString("%1").arg(lenBez);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -57,13 +57,13 @@ void TST_VEllipticalArc::CompareTwoWays()
const QString errorMsg = const QString errorMsg =
QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps);
QVERIFY2(qAbs(arc1.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc1.GetLength() - length) <= eps, qUtf8Printable(errorMsg));
//QVERIFY2(arc2.GetLength() - length <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc2.GetLength() - length) <= eps, qUtf8Printable(errorMsg));
//QVERIFY2(arc1.GetLength() - arc2.GetEndAngle() <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc1.GetLength() - arc2.GetLength()) <= eps, qUtf8Printable(errorMsg));
// compare angles // compare angles
//QVERIFY2(arc1.GetEndAngle() - arc2.GetEndAngle() <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc1.GetEndAngle() - arc2.GetEndAngle()) <= eps, qUtf8Printable(errorMsg));
//QVERIFY2(arc1.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= eps, qUtf8Printable(errorMsg));
//QVERIFY2(arc1.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= eps, qUtf8Printable(errorMsg));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -78,14 +78,15 @@ void TST_VEllipticalArc::NegativeArc()
const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2));
const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/2; const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/2;
VEllipticalArc arc(-length, center, radius1, radius2, f1); qreal l = -length;
VEllipticalArc arc(l, center, radius1, radius2, f1);
const qreal eps = 1; // computing error const qreal eps = 1; // computing error
const QString errorMsg = const QString errorMsg =
QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps);
//QVERIFY2(qAbs(arc.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc.GetLength() + length) <= eps, qUtf8Printable(errorMsg));
//QVERIFY2(arc.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); QVERIFY2(arc.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg));
} }
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction