checking if two polygons touch each other

Discussion forum for contributors and developers who are using the QCAD ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Post Reply
sarlaa
Active Member
Posts: 47
Joined: Mon Aug 28, 2017 4:39 pm

checking if two polygons touch each other

Post by sarlaa » Fri May 25, 2018 5:24 pm

Hi,

I need to know if two polygon shapes touch each other.

You showed me how to use RPolygonClipper with union mode (RS.Union) :

Code: Select all

var clipper = new RPolygonClipper();

// add subject paths (islands: ccw, holes: cw):
clipper.addSubjectPath([new RVector(0,0), new RVector(100,0), new RVector(100,100), new RVector(0,100)]);
clipper.addSubjectPath([new RVector(50,50), new RVector(150,50), new RVector(150,150), new RVector(50,150)]);

// union:
clipper.execute(RS.Union, RS.NonZero);

// print result:
for (var c=0; c<clipper.getSolutionPathCount(); c++) {
    var vertices = clipper.getSolutionPath(c);
    qDebug("polygon:", vertices);
}
So I'm thinking to use RPolygonClipper with intersection mode if exists ?
And I can check if results points are on the same line.
could you show me if it exists how ?

Thanks !

User avatar
andrew
Site Admin
Posts: 5604
Joined: Fri Mar 30, 2007 6:07 am

Re: checking if two polygons touch each other

Post by andrew » Fri May 25, 2018 7:19 pm

You can find the intersection points between two polylines using getIntersectionPoints:

Code: Select all

var pl1 = new RPolyline();
pl1.setVertices([new RVector(0,0), new RVector(100,0), new RVector(100,100)]);

var pl2 = pl1.copy();
pl2.move(new RVector(10,10));

var ips = pl1.getIntersectionPoints(pl2);
qDebug(ips);
Output:

Code: Select all

RVector(100, 10, 0, true)

Post Reply

Return to “QCAD Developers and Contributors”