Method intersection circles.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-05-25 15:49:28 +03:00
parent 8980db725d
commit 1ba4725538
2 changed files with 28 additions and 0 deletions

View File

@ -260,6 +260,19 @@ QPointF VGObject::LineIntersectRect(const QRectF &rec, const QLineF &line)
return point; 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. * @brief LineIntersectCircle find point intersection line and circle.
@ -416,6 +429,18 @@ double VGObject::GetEpsilon(const QPointF &p1, const QPointF &p2)
return epsilon; 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. * @brief GetReversePoint return revers container of points.

View File

@ -73,6 +73,8 @@ public:
static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect); static QLineF BuildAxis(const QPointF &p1, const QPointF &p2, const QRectF &scRect);
static QPointF LineIntersectRect(const QRectF &rec, const QLineF &line); 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 &center, qreal radius, const QLineF &line, QPointF &p1, static qint32 LineIntersectCircle(const QPointF &center, qreal radius, const QLineF &line, QPointF &p1,
QPointF &p2); QPointF &p2);
static QPointF ClosestPoint(const QLineF &line, const QPointF &point); 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 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 PerpDotProduct(const QPointF &t, const QPointF &p1, const QPointF &p2);
static double GetEpsilon(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 #endif // VGOBJECT_H