58 #include "../vmisc/vmath.h"
60 #ifdef Q_COMPILER_RVALUE_REFS
96 qreal kCurve, quint32 idObject,
Draw mode)
98 d(new
VSplineData(p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve))
134 const QString &angle2Formula, qreal c1Length,
const QString &c1LengthFormula, qreal c2Length,
135 const QString &c2LengthFormula, quint32 idObject,
Draw mode)
137 d(new
VSplineData(p1, p4, angle1, angle1Formula, angle2, angle2Formula, c1Length, c1LengthFormula, c2Length,
206 static_cast<QPointF
>(
GetP4()));
216 const QPointF cutPoint =
CutSpline (length, spl1p2, spl1p3, spl2p2, spl2p3 );
231 static_cast<QPointF
>(
GetP3()),
static_cast<QPointF
>(
GetP4()));
248 qreal kAsm2, qreal kCurve)
250 QLineF p1pX(p1.x(), p1.y(), p1.x() + 100, p1.y());
251 p1pX.setAngle( angle1 );
252 qreal L = 0, radius = 0, angle = 90;
253 radius = QLineF(QPointF(p1.x(), p4.y()), p4).length();
254 L = kCurve * radius * 4 / 3 * tan( angle * M_PI_4 / 180.0 );
255 QLineF p1p2(p1.x(), p1.y(), p1.x() + L * kAsm1, p1.y());
256 p1p2.setAngle(angle1);
257 QLineF p4p3(p4.x(), p4.y(), p4.x() + L * kAsm2, p4.y());
258 p4p3.setAngle(angle2);
259 QPointF p2 = p1p2.p2();
260 QPointF p3 = p4p3.p2();
267 if ( &spline ==
this )
299 QLineF p1p2(
d->p1.x(),
d->p1.y(),
d->p1.x() +
d->c1Length,
d->p1.y());
300 p1p2.setAngle(
d->angle1);
311 QLineF p4p3(
d->p4.x(),
d->p4.y(),
d->p4.x() +
d->c2Length,
d->p4.y());
312 p4p3.setAngle(
d->angle2);
368 d->angle1F = formula;
375 d->angle2F = formula;
405 d->c1Length = length;
406 d->c1LengthF = formula;
412 d->c2Length = length;
413 d->c2LengthF = formula;
423 return QLineF(
static_cast<QPointF
>(
d->p1),
static_cast<QPointF
>(
GetP2())).length() /
434 return QLineF(
static_cast<QPointF
>(
d->p4),
static_cast<QPointF
>(
GetP3())).length() /
451 if (qAbs(ld)<0.00000000001)
455 return (ld>0) ? 1 : -1;
480 const qreal q = (pow(a, 2) - 3*b)/9.;
481 const qreal r = (2*pow(a, 3) - 9*a*b + 27.*c)/54.;
482 if (pow(r, 2) < pow(q, 3))
484 const qreal t = acos(r/sqrt(pow(q, 3)))/3.;
485 x.insert(0, -2.*sqrt(q)*cos(t)-a/3);
486 x.insert(1, -2.*sqrt(q)*cos(t + (2*
M_2PI/3.)) - a/3.);
487 x.insert(2, -2.*sqrt(q)*cos(t - (2*
M_2PI/3.)) - a/3.);
493 const qreal aa = -
Sign(r)*pow(fabs(r)+sqrt(pow(r, 2)-pow(q, 3)), 1./3.);
494 const qreal bb =
Sign(aa) == 0 ? 0 : q/aa;
496 x.insert(0, aa+bb-a/3.);
497 x.insert(1, (-0.5)*(aa+bb)-a/3.);
498 x.insert(2, (sqrt(3.)*0.5)*fabs(aa-bb));
499 if (qFuzzyIsNull(x.at(2)))
509 qreal curveCoord4, qreal pointCoord)
const
511 const qreal a = -curveCoord1 + 3*curveCoord2 - 3*curveCoord3 + curveCoord4;
512 const qreal b = 3*curveCoord1 - 6*curveCoord2 + 3*curveCoord3;
513 const qreal c = -3*curveCoord1 + 3*curveCoord2;
514 const qreal
d = -pointCoord + curveCoord1;
520 for (
int i=0; i < t.size(); ++i)
522 if ( t.at(i) >= 0 && t.at(i) <= 1 )
524 retT.append(t.at(i));
557 for (
int i=0; i< ts.size(); ++i)
559 const qreal t = ts.at(i);
560 const QPointF p0 =
static_cast<QPointF
>(
GetP1());
561 const QPointF p1 =
static_cast<QPointF
>(
GetP2());
562 const QPointF p2 =
static_cast<QPointF
>(
GetP3());
563 const QPointF p3 =
static_cast<QPointF
>(
GetP4());
565 const qreal pointX = pow(1-t, 3)*p0.x() + 3*pow(1-t, 2)*t*p1.x() + 3*(1-t)*pow(t, 2)*p2.x() + pow(t, 3)*p3.x();
566 const qreal pointY = pow(1-t, 3)*p0.y() + 3*pow(1-t, 2)*t*p1.y() + 3*(1-t)*pow(t, 2)*p2.y() + pow(t, 3)*p3.y();
568 const QLineF line(pBt, QPointF(pointX, pointY));
569 if (line.length() <= eps)
582 return static_cast<QPointF
>(
GetP2 ());
588 return static_cast<QPointF
>(
GetP3 ());
VAbstractCubicBezier & operator=(const VAbstractCubicBezier &curve)
static qreal LengthBezier(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
LengthBezier return spline length using 4 spline point.
virtual void CreateName() Q_DECL_OVERRIDE
static QVector< QPointF > GetCubicBezierPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
GetCubicBezierPoints return list with cubic bezier curve points.
QString getLineWeight() const
getLineWeight return weight of the lines
void SetPenStyle(const QString &penStyle)
void setLineColor(const QString &color)
void setLineWeight(const QString &lineWeight)
setLineWeight set weight of the lines
QString GetPenStyle() const
void Swap(VAbstractCurve &curve) Q_DECL_NOTHROW
QString getLineColor() const
virtual QString name() const
name return name graphical object.
void setName(const QString &name)
setName set name graphical object.
The VPointF class keep data of point.
static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees)
static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle)
VPointF Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix=QString()) const
VPointF Flip(const QLineF &axis, const QString &prefix=QString()) const
qreal y() const
y return y coordinate
VPointF Move(qreal length, qreal angle, const QString &prefix=QString()) const
static QPointF FlipPF(const QLineF &axis, const QPointF &point)
qreal x() const
x return x coordinate
static qreal GetL(const QPointF &p1, const QPointF &p4, qreal kCurve)
VSpline class that implements the spline.
virtual qreal GetLength() const Q_DECL_OVERRIDE
GetLength return length of spline.
VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix=QString()) const
virtual QPointF GetControlPoint2() const Q_DECL_OVERRIDE
static qint32 Cubic(QVector< qreal > &x, qreal a, qreal b, qreal c)
Cubic Cubic equation solution. Real coefficients case.
virtual qreal GetC2Length() const Q_DECL_OVERRIDE
virtual VPointF GetP4() const Q_DECL_OVERRIDE
GetP4 return last spline point.
void SetP4(const VPointF &p)
void SetC1Length(qreal length, const QString &formula)
QString GetC1LengthFormula() const
VSpline()
VSpline default constructor.
qreal GetKcurve() const
GetKcurve return coefficient of curvature spline.
void SetC2Length(qreal length, const QString &formula)
VSpline & operator=(const VSpline &spline)
virtual qreal GetStartAngle() const Q_DECL_OVERRIDE
GetAngle1 return first angle control line.
void SetP1(const VPointF &p)
qreal ParamT(const QPointF &pBt) const
VSpline::ParamT calculate t coeffient that reprezent point on curve.
VSpline Flip(const QLineF &axis, const QString &prefix=QString()) const
virtual VPointF GetP1() const Q_DECL_OVERRIDE
GetP1 return first spline point.
virtual VPointF GetP2() const Q_DECL_OVERRIDE
GetP2 return first control point.
QString GetStartAngleFormula() const
QString GetEndAngleFormula() const
qreal GetKasm1() const
GetKasm1 return coefficient of length first control line.
static QVector< QPointF > SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve)
SplinePoints return list with spline points.
QPointF CutSpline(qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const
CutSpline cut spline.
virtual qreal GetC1Length() const Q_DECL_OVERRIDE
void Swap(VSpline &spline) Q_DECL_NOTHROW
virtual VPointF GetP3() const Q_DECL_OVERRIDE
GetP3 return second control point.
QString GetC2LengthFormula() const
VSpline Move(qreal length, qreal angle, const QString &prefix=QString()) const
QVector< qreal > CalcT(qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, qreal curveCoord4, qreal pointCoord) const
void SetStartAngle(qreal angle, const QString &formula)
virtual QVector< QPointF > getPoints() const Q_DECL_OVERRIDE
GetPoints return list with spline points.
virtual qreal GetEndAngle() const Q_DECL_OVERRIDE
GetAngle2 return second angle control line.
void SetEndAngle(qreal angle, const QString &formula)
QSharedDataPointer< VSplineData > d
virtual QPointF GetControlPoint1() const Q_DECL_OVERRIDE
static int Sign(long double ld)
qreal GetKasm2() const
GetKasm2 return coefficient of length second control line.