I have not started any coding so far, and I'm not sure I will any time soon, I just want to share the thoughts.
Design goals:
1. Support high-degree Beziers (up to OCC's maximum of 25)
2. Support for insertion and removal of control points (aka poles)
3. Support for point-on-curve and tangent/perp./angle-via-point. And, coincident for endpoints and control points, of course.
4. Support constraining points to self-intersections.
5. (not essential) Trimmed Bezier support.
Here are a few challenges.
challenge 1. Control points
As some may know, Sketcher code supports only three points per object: start point, and point, middle point. That means, there can be only three points on the screen being part of Bezier, which is really not acceptable.
I see at least two ways of adding the control points:
1. Using internal alignment constraints, the necessary points will be constrained to the Bezier.
There are a few disadvantages of the approach:
- a lot of bloat in constraint list and element list
- the control points are not visually distinguishable
- potentially slow because of the bloat: lots of constraints means larger matrix to analyze (not solve?), and lots of geometry (points) to copy around (which is done a lot there)
2. Extending Sketcher code to support the control points. E.g. positive values of pointpos are the usual start/end/middle, but negative values are index of control point.
+ minimal bloat
- elements widget will need a rework
+ control points can be rendered differently, becoming visually obvious.
challenge 2. Point-on-curve constraint
I have thought about it a bit, and I think that the constraint has to be different from the existing by that it should keep track of the parameter value associated with the point. This is because I'm unable to formulate an error function for the regular constraint, and I believe even if it is possible to formulate such a function, the constraint will behave extremely poor if the Bezier has self-intersections. Moreover, knowing the t parameter of the point allows easy computation of tangent and normal vectors, required for angle, tangent and perpendicular constraints.
Again, I see two ways of implementing it:
1. introduce new type of point - a point that is forever stuck on a curve, and knows its t value.
+ point knows its t -> easy to calculate tangent/normal.
+ the points can be used to set trim to the curve
- confusion for users
2. introduce a new type of point-on-curve constraint - a datum version of one. This path requires to implement measurement constraints (the constraint that computes its value, rather than enforcing it). I know there are a few requests for this already on the forum, and it seems to be a good excuse for actually fulfilling the requests.
- finding out point's t requires linkage to the constraint -> tricky code.
- tricky code to trim the curve
+ fits well into existing workflow
+ bonus - measurement constraints
+ ability to fix t is valuable itself -> new feature for existing shapes
That's it so far
