diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index 6a66bd978..d2ca296c1 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -260,6 +260,19 @@ QPointF VGObject::LineIntersectRect(const QRectF &rec, const QLineF &line) return point; } +//--------------------------------------------------------------------------------------------------------------------- +int VGObject::IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, QPointF &p2) +{ + if (qFuzzyCompare(c1.x(), c2.x()) && qFuzzyCompare(c1.y(), c2.y()) && qFuzzyCompare(r1, r2)) + { + return 3;// Circles are equal + } + const double a = 2.0 * (c2.x() - c1.x()); + const double b = 2.0 * (c2.y() - c1.y()); + const double c = c1.x() * c1.x() + c1.y() * c1.y() - r1 * r1 - (c2.x() * c2.x() + c2.y() * c2.y() - r2 * r2); + return LineIntersectCircle (c1, r1, CreateSegment(a, b, c), p1, p2); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief LineIntersectCircle find point intersection line and circle. @@ -416,6 +429,18 @@ double VGObject::GetEpsilon(const QPointF &p1, const QPointF &p2) return epsilon; } +//--------------------------------------------------------------------------------------------------------------------- +QLineF VGObject::CreateSegment(double a, double b, double c) +{ + const double x1 = 0; + const double y1 = (-a*x1-c)/b; + + const double x2 = 1000; + const double y2 = (-a*x2-c)/b; + + return QLineF(x1, y1, x2, y2); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetReversePoint return revers container of points. diff --git a/src/libs/vgeometry/vgobject.h b/src/libs/vgeometry/vgobject.h index 5ad5d0b7c..2e32741b3 100644 --- a/src/libs/vgeometry/vgobject.h +++ b/src/libs/vgeometry/vgobject.h @@ -73,6 +73,8 @@ public: static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect); static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line); + static int IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, + QPointF &p2); static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, QPointF &p2); static QPointF ClosestPoint(const QLineF &line, const QPointF &point); @@ -88,6 +90,7 @@ private: static bool IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QPointF &p2); static double PerpDotProduct(const QPointF &t, const QPointF &p1, const QPointF &p2); static double GetEpsilon(const QPointF &p1, const QPointF &p2); + static QLineF CreateSegment(double a, double b, double c); }; #endif // VGOBJECT_H