bezier patch with 3 bezier curves.

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
pat_oneil
Posts: 36
Joined: Wed Jun 17, 2015 2:36 am

Re: bezier patch with 3 bezier curves.

Post by pat_oneil »

Where can I find some documentation on the bezier methods? Do I need the python source code?

The segment function requires two parameters for a cubic bezier so I guessed(0.5,0.5) but did not get what I expected. I also tried other values but did not get anything expected.

I wanted to split the bezier curve using FreeCad and compare the poles to the ones I was feeding it to see if they matched.
If they matched, I was going to replace my edges with the generated segments and see if that solved my problem.
emills2
Posts: 889
Joined: Tue Apr 28, 2015 11:23 pm

Re: bezier patch with 3 bezier curves.

Post by emills2 »

documentation in general: just guess what the function would want as parameters if you had written it yourself :lol:. after failing a few times come ask here!

[edit: i'm sure you're aware, but just in case...the FreeCAD python interpreter has a class browser. sometimes parameter info is incomplete, but still pretty useful
Screenshot_classbrowser.jpg
Screenshot_classbrowser.jpg (31.15 KiB) Viewed 802 times
in this case,type
import Part
mybeziercurve = Part.BezierCurve()
and then
mybeziercurve.
right after you type the ',' the browser appears.]

Bezier curves are 3D functions of a parameter, typically called t, u or v.

typically the parameter runs from 0 to 1. 0 is the start of the curve (first control point), 1 is the end of the curve (last control point). Notice that this gives each curve a definite direction.

you can inspect these with:
mybeziercurve.FirstParameter
mybeziercurve.LastParameter

these are 'properties', they return the value without changing anything

segment works like this:

mybeziercurve.segment(new_start_parameter, new_end_parameter)

this CUTS your EXISTING curve. it throws away everything BEFORE new_start_parameter, and AFTER new_end_parameter

so for the first half of a curve, you want
a=mybeziercurve.FirstParameter
b=mybeziercurve.LastParameter
c=(a+b)/2
mybeziercurve.segment(a,c) # most of the time, this turns out to be (0,0.5)

next problem: now we lost our original curve! how are we going to get the other half?

just make a copy, and segment the copy. There are a few pass by reference/pass by value landmine across FreeCAD/python.
this means that
A=4
B=A
B.change() # changes A as well, which is almost never what you want.

I don't remember how to do a clean copy of this specific case off the top of my head.

if worse comes to worse, you can always .getpoles() of the original curve, make a new curve, .setpoles() to clone the original, segment() the clone....make another clone....segment the other clone. That's just the worst case if you need it NOW. otherwise experiment.
pat_oneil
Posts: 36
Joined: Wed Jun 17, 2015 2:36 am

Re: bezier patch with 3 bezier curves.

Post by pat_oneil »

Well, what a saga, journey, missteps....

It seems one of the reason I was having trouble with two edges intersecting 1 edge was precision.

I had thought that 3 decimal points on mm scale was sufficient but it was not. When I just kept all of the floating point precision, most of the problem was solved. The good news (for me) is that my split routine in JavaScript generated the same results as python.

SO.... The remaining problem with both split side and "null" edge approach is that a subtraction of a cube from the fused extruded faces fails if the cube edge intersects the split or null vertex. HOWEVER, I was able to perform the same operation by extruding each face separately, subtracting the cube from each and then fusing the extrusions together. Same results, difference sequence, strange.

Anyway, I can easily live with the workaround if it actually becomes a problem. Thanks for all of your help. I would never got to the finish line without your help.
Post Reply