FS#2620 - No intersections returned for an RSpline (fitPoints) and an RCircle
Andrew,
Related to this Forum topic
(ArcTPR.js: Offsets to an ellipse are fit-point splines)
The array of intersections of a fit-point spline and a circle is always empty.
The method is broken ...
OR
The method is not implemented at all without mentioning it ...!?
(Already failing with QCAD 3.27.6.0)
Workaround 1:
Quote: If we trim or cut up a fit-Point spline the result(s) is/are (a) control-point spline(s).
If any, the intersections between these splines and a circle are valid.
Downside:
If the circle crosses the cutting point (or the start=end point when closed) then
two identical intersections are included.
Workaround 2: Approximate the fit-point spline with a polyline (Explode).
Expected are approximate intersections.
Unaware if that is the method used for intersections internally.
Below a simple script that can be run with XC:
→ No intersections as fit-point spline
→ 4 intersections as control-Point spline segments (Workaround 1)
// Example points to fit:
var fitpoints = [new RVector(0, 9),
new RVector(7, 0),
new RVector(0, -9),
new RVector(-7, 0)];
// Create a spline shape:
var spline = new RSpline();
spline.setFitPoints(fitpoints);
spline.setPeriodic(true);
// Create a circle shape:
var circle = new RCircle(RVector.nullVector, 8.0);
// Get intersections of spline and circle, expecting 4:
var ips1 = spline.getIntersectionPoints(circle, false);
// Report the number of intersections on the Command History:
EAction.handleUserInfo("As fit-point spline: %1 intersections (of 4)".arg(ips1.length));
// Cut up the spline in two parts -> Control-Point spline
var cutPoint = spline.getTMin() + (spline.getTDelta()/2.0); // fitPoint (0, -9)
var splines = spline.splitAtParams([cutPoint]);
// Get intersections of both spline segments and circle:
var ips2 = splines[0].getIntersectionPoints(circle, false);
ips2 = ips2.concat(splines[1].getIntersectionPoints(circle, false));
// Report the number of intersections on the Command History:
EAction.handleUserInfo("As control-point splines: %1 intersections (of 4)".arg(ips2.length));
Regards,
CVH
Found another solution ...
If we swap the RShapes in the above code then all is OK.
I assumed that the order didn't matter.
RShape::getIntersectionPoints(shape1, shape2, limited, same, force)
Returns practically the same thing as it dynamically swaps both shapes:
Circle vs Spline ⇒ return getIntersectionPointsCS(*circle1, *spline2, limited);
Spline vs Circle ⇒ return getIntersectionPointsCS(*circle2, *spline1, limited);
However, this is no solution for ArcTPR.js
Swapping the order of shapes in the original code:
// Replace: // find potential centers for arc: var ips = parallel.getIntersectionPoints(circle, false); // With: // find potential centers for arc: var ips = circle.getIntersectionPoints(parallel, false);Will throw an error: RShape: Argument 0 is not of type RShape*.
Argument 0 or the spline is indeed a QSharedPointer. (Reference)
Can it be that it must be 2 RShape's or at least an RShape as argument?
Regards,
CVH
More on the subject in this forum topic.
With examples, visualization, recent code and so on.
Regards,
CVH