Hi,
Please, could you tell me if there is a way to construct a shape base on fusion of other shapes like the piture attached :
newShape = fusion([Shape1, Shape2, Shape3]);
Many thanks!
Caramel
Fusion of shapes
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Fusion of shapes
- Attachments
-
- shapesFusion.PNG (65.94 KiB) Viewed 7407 times
Re: Fusion of shapes
Hi Caramel,
Welcome to the forum.
Welcome to the forum.
That should be easy using the "break out segment" (D2) tool, just click on the segments you wish to remove.Please, could you tell me if there is a way to construct a shape base on fusion of other shapes like the piture attached
JJ Win7 pro-64
Re: Fusion of shapes
Presumably, you are looking for a programmatic way (since you posted to the developer forum).
For polygon shapes (i.e. only straight segments), you can use clipper which comes with QCAD Professional:
For polygon shapes (i.e. only straight segments), you can use clipper which comes with QCAD Professional:
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);
}
Re: Fusion of shapes
Hi andrew,
Thanks for your response,
Yes I'm looking for a programmatic way and just for polygon shapes (with straight segments).
I tested your code with QCAD Professional and it works,
But when I test with other shapes :
I get these results :
polygon: RVector(12, 2, 0, true),RVector(10, 2, 0, true),RVector(10, 10, 0, true),RVector(0, 10, 0, true),RVector(0, 2, 0, true),
RVector(10, 2, 0, true),RVector(10, 0, 0, true),RVector(0, 0, 0, true),RVector(0, 2, 0, true),
RVector(-2, 2, 0, true),RVector(-2, -2, 0, true),RVector(12, -2, 0, true)
area: 116
When I excpect these results :
polygon expected: RVector(12, 2, 0, true),RVector(10, 2, 0, true),RVector(10, 10, 0, true),RVector(0, 10, 0, true),RVector(0, 2, 0, true),
RVector(-2, 2, 0, true),RVector(-2, -2, 0, true),RVector(12, -2, 0, true)
area expected: 136
Is this a bug ?
Thanks for your response,
Yes I'm looking for a programmatic way and just for polygon shapes (with straight segments).
I tested your code with QCAD Professional and it works,
But when I test with other shapes :
Code: Select all
var clipper = new RPolygonClipper();
clipper.addSubjectPath([new RVector(0,0), new RVector(10,0), new RVector(10,10), new RVector(0,10)]);
clipper.addSubjectPath([new RVector(-2,2), new RVector(12,2), new RVector(12,-2), new RVector(-2,-2)]);
// 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)
qDebug("area:" , Mod_Line2P.getArea(vertices))
}
I get these results :
polygon: RVector(12, 2, 0, true),RVector(10, 2, 0, true),RVector(10, 10, 0, true),RVector(0, 10, 0, true),RVector(0, 2, 0, true),
RVector(10, 2, 0, true),RVector(10, 0, 0, true),RVector(0, 0, 0, true),RVector(0, 2, 0, true),
RVector(-2, 2, 0, true),RVector(-2, -2, 0, true),RVector(12, -2, 0, true)
area: 116
When I excpect these results :
polygon expected: RVector(12, 2, 0, true),RVector(10, 2, 0, true),RVector(10, 10, 0, true),RVector(0, 10, 0, true),RVector(0, 2, 0, true),
RVector(-2, 2, 0, true),RVector(-2, -2, 0, true),RVector(12, -2, 0, true)
area expected: 136
Is this a bug ?
Re: Fusion of shapes
I think you might have missed the bit in the code about islands being CCW (counter-clockwise) and holes being CW (clockwise). Your second polygon is CW, hence treated as hole.
You might want to use RPolyline::getOrientation() to check for orientation CW or CCW, RPolyline::reverse() to reverse and RPolyline::getArea() to compute the area.
You might want to use RPolyline::getOrientation() to check for orientation CW or CCW, RPolyline::reverse() to reverse and RPolyline::getArea() to compute the area.
Re: Fusion of shapes
You have absolutely right, I missed with orientation as you mentioned, now I get the exact expect results.
Thanks a lot !
Thanks a lot !