Page 1 of 1

checking if two polygons touch each other

Posted: Fri May 25, 2018 5:24 pm
by sarlaa
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 !

Re: checking if two polygons touch each other

Posted: Fri May 25, 2018 7:19 pm
by andrew
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)