Sketcher: Bezier curves

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Sketcher: Bezier curves

Post by microelly2 »

abdullah wrote:
saso wrote:Since 8 is a nice number :roll: how about adding support for bezier curves to draft -> draft to sketch tool?
Draft is Python. I do not have the competence to do any decent Python. Sorry! :oops:
I have already played with some convertings
https://www.youtube.com/watch?v=4gri-q-bw9k
at that time the sketcher interface was easy to use: create the sketcher splines from point clouds, so Draft BSplines <-> Sketcher BSplines will come.
At the moment its too much dynamic in the sketcher project. Let's wait until it has finished ;)
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Sketcher: Bezier curves

Post by microelly2 »

bp_406.png
bp_406.png (37.42 KiB) Viewed 1915 times
Here is a method to convert a Draft BSpline into a Sketcher Bspline
https://github.com/microelly2/freecad-n ... hspline.py

https://www.youtube.com/watch?v=Dh5jUAdPp5I&t=440s
So the way is open from a hand drawn picture to a parametric bspline curve.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Bezier curves

Post by abdullah »

microelly2 wrote:Here is a method to convert a Draft BSpline into a Sketcher Bspline
https://github.com/microelly2/freecad-n ... hspline.py

https://www.youtube.com/watch?v=Dh5jUAdPp5I&t=440s
So the way is open from a hand drawn picture to a parametric bspline curve.
Beautiful. You do have a gift for giving new uses to existing tools :)
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Bezier curves

Post by abdullah »

wmayer wrote: Attached is a sketch to demonstrate the behaviour.

The problem is caused by this line in ViewProviderSketch.cpp:

Code: Select all

repscale = ( 0.5 * maxdisttocenterofmass ) / maxcurv; 
because it computes an individual scaling factor for each curve. But what we need is a fix scaling factor for all curves.
I find very interesting this geometric construction of C1 and C2 continuities.

While I do understand what you are saying, I am not sure how a curvature comb should look in the intersection. So I just fixed the problem you identified. Now the scale is general for all bsplines in a sketch.

The last commit in this branch should fix the problem:

https://github.com/abdullahtahiriyo/Fre ... eliverable

Let me know if it is not ok.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Bezier curves

Post by abdullah »

1. Fix curvature comb as indicated by Werner
2. Implement decrease knot multiplicity
3. Review return types in functions (I have some boolean returning functions that should probably better off by returning nothing and raising an exception if something happens)
4. Ask for icons and integrate icons.
5. Fix annoying bug that crashes FC when undo is effected after a multiplicity change.
6. Do something so that FC compiled against OCC<6.9.0 does not crash.
7. Check Werner's solver test case issue.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Sketcher: Bezier curves

Post by microelly2 »

abdullah wrote:1. Fix curvature comb as indicated by Werner
2. Implement decrease knot multiplicity
Nice to see knot reduction on top of your list. :geek:
I have played yesterday on this problem to simplify my scan-based layouts.
https://forum.freecadweb.org/viewtopic. ... 70#p165427

one other big step for me would be a constraint "pole is on the curve"
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Bezier curves

Post by abdullah »

wmayer wrote:Very often the travis or AppVeyor builds fail because of this error:
======================================================================
ERROR: testSlotCase (TestSketcherApp.SketcherSolverTestCases)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\projects\freecad\build\Mod\Sketcher\TestSketcherApp.py", line 113, in testSlotCase
CreateSlotPlateSet(self.Slot)
File "C:\projects\freecad\build\Mod\Sketcher\TestSketcherApp.py", line 61, in CreateSlotPlateSet
SketchFeature.setDatum(9,200.000000)
ValueError: Cannot set the datum because the sketch contains conflicting constraints
----------------------------------------------------------------------
If wonder why this happens and how it can be fixed.
I would say the reason is this:
https://forum.freecadweb.org/viewtopic. ... 10#p165588

The proposed fix is this:
https://github.com/abdullahtahiriyo/Fre ... 3e22e61b76

I have not removed the coincidents. It should not be needed according to my tests. If it fails after the merge, then probably we should just remove them and rewrite the test with the new constraint indexes.

:)
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Bezier curves

Post by abdullah »

microelly2 wrote:
abdullah wrote:1. Fix curvature comb as indicated by Werner
2. Implement decrease knot multiplicity
Nice to see knot reduction on top of your list. :geek:
I have played yesterday on this problem to simplify my scan-based layouts.
https://forum.freecadweb.org/viewtopic. ... 70#p165427

one other big step for me would be a constraint "pole is on the curve"
Sorry MicroElly, I cheated:

1. Fix curvature comb as indicated by Werner
2. Implement decrease knot multiplicity
3. Review return types in functions (I have some boolean returning functions that should probably better off by returning nothing and raising an exception if something happens)
4. Ask for icons and integrate icons.
5. Fix annoying bug that crashes FC when undo is effected after a multiplicity change.
6. Do something so that FC compiled against OCC<6.9.0 does not crash.
7. Check Werner's solver test case issue.

I probably will continue cheating, as I would like to get rid of 5, because this will replicate when implementing knot reduction. Somehow, because the sketchobject function is modifyrank, sooner or later I will have to do it.

I saw your other topic with the tolerance for rank reduction. I am not sure how to handle this tolerance. I was not planning on asking the user, but iteratively increasing the tolerance. However, now I realize that maybe the user want to smooth (so not using the smallest possible tolerance)... any input is welcome.

EDIT: You mean point on object (pole point on BSpline curve?)
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Sketcher: Bezier curves

Post by microelly2 »

abdullah wrote:[
I saw your other topic with the tolerance for rank reduction. I am not sure how to handle this tolerance. I was not planning on asking the user, but iteratively increasing the tolerance. However, now I realize that maybe the user want to smooth (so not using the smallest possible tolerance)... any input is welcome.
when I want to delete a knot, I calculate all possibilities , display them and calculate the tolerance value.
sometimes the least square minimum is not the figure I prefer,

I have the opportunity to select my favourite and delete the others, no idea how a parametric sketch solver can do this.
maybe that this is the horizon from CAD to CAA (computer aided art) :lol:
EDIT: You mean point on object (pole point on BSpline curve?)
yes, the pole point is on the curve (a knot with a higher multiplicity)
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: Bezier curves

Post by abdullah »

microelly2 wrote:yes, the pole point is on the curve (a knot with a higher multiplicity)
A pole will be on the curve naturally, without any constraint when sufficiently increasing the multiplicity of the knot:
knotHigherMult.png
knotHigherMult.png (16.12 KiB) Viewed 1745 times
This can be done in my development branch (but do not try to undo it afterwards yet ;) )
Post Reply