var drawPolyline = function (rPolyline) { var op = new RAddObjectsOperation(); var entity = new RPolylineEntity(document, new RPolylineData(rPolyline)); op.addObject(entity); op.apply(document); return document.queryEntity(entity.getId()); }; var drawSpline = function (rSpline) { var op = new RAddObjectsOperation(); var spline = new RSplineEntity(document, new RSplineData(rSpline)); op.addObject(spline, false); op.apply(document); return document.queryEntity(spline.getId()); }; var n1 = new RVector(0, 0); var n2 = new RVector(50, 50); var n3 = new RVector(60, 30); var n4 = new RVector(40, 20); var r1Shape = drawPolyline(new RPolyline([n1, n2, n3, n4], false)).getData().castToShape(); var n5 = new RVector(20, 0); var n6 = new RVector(30, 60); var n7 = new RVector(40, 30); var r2 = new RSpline(); r2.appendFitPoint(n5); r2.appendFitPoint(n6); r2.appendFitPoint(n7); var r2Shape = drawSpline(r2).getData().castToShape(); var r3 = new RSpline(); r3.appendFitPoint(n1); r3.appendFitPoint(n2); r3.appendFitPoint(n3); r3.appendFitPoint(n4); var r3Shape = drawSpline(r3).getData().castToShape(); print(r1Shape.getIntersectionPoints(r2Shape, false)); // not show intersection points print(r3Shape.getIntersectionPoints(r2Shape, false)); // RVector(23.5319, 41.9233, 0, true),RVector(33.7983, 51.6832, 0, true)
How to get intersection points between polyline with another
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
How to get intersection points between polyline with another
I try with lasted QCAD Pro (3.13.1) but can not get intersection points between polyline with another entity. Help me, please
Re: How to get intersection points between polyline with ano
Can you attach the drawing as DXF file please? Thanks.
Re: How to get intersection points between polyline with ano
Here is dxf file generated from above code
- Attachments
-
- test.dxf
- (182.45 KiB) Downloaded 393 times
Re: How to get intersection points between polyline with ano
The .getData().castToShape() construct is generally not a good idea since a data object is created (but not used) and a pointer to it's shape is retrieved which is well used. The data object will get deleted by the garbage collector and the pointer will become invalid.
I'd refactor as follows:
I'd refactor as follows:
var r1Shape = new RPolyline([n1, n2, n3, n4], false); drawPolyline(r1Shape); ... var r2Shape = new RSpline(); r2Shape.appendFitPoint(n5); r2Shape.appendFitPoint(n6); r2Shape.appendFitPoint(n7); drawSpline(r2Shape);
Re: How to get intersection points between polyline with ano
Thank Andrew, I understand, can easy get intersection point from 2 shapes: RSpline & RPolyline
But, if I only have entities (not have RShape),
But, if I only have entities (not have RShape),
r1 = RPolylineEntity(...) // this is RPolylineEntityPointer r2 = RSpline(...) // this is RSplineEntityPointer // From here, how to get intersection of 2 entities ? var getIntersectionPoints = function (limitEntity, trimEntity, limited) { limited = limited || false; var limitShape = limitEntity.getData().castToShape(); var trimShape = trimEntity.getData().castToShape(); return trimShape.getIntersectionPoints(limitShape, limited); }; print(getIntersectionPoints(r1, r2));Can you help me solve getIntersectionPoints function? I attach snippet autostart file below
- Attachments
-
- intersection_polyline.js
- (1.46 KiB) Downloaded 363 times
Re: How to get intersection points between polyline with ano
REntity based classes also have a getIntersectionPoints method:
limitEntity.getIntersectionPoints(trimEntity, limited);
Re: How to get intersection points between polyline with ano
Done. Thank you so much