Easiest way to find the distance between two parallel QLineF?
General and Desktop
2
Posts
2
Posters
975
Views
1
Watching
-
From the math point of view, I guess the following should work (I'm tempted to say it's impossible to do it "simpler", but implementing the same operations using your own specialized code might be more performant):
@QLineF normal = line1,normal();.
QPointF crossPoint;
if (normal.intersect(line2, &crossPoint) != QLineF::NoIntersection) {
QLineF distanceLine(line1.p1(), crossPoint);
qreal distance = distanceLine.length();
}@
Please note there is no check for actual parallelity; you can add it be comparison of the inclinations:
@if (line1.dy() * line2.dx() == line1.dx() * line2.dy()) {
// parallel
} else {
// not parallel
}@