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!
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: bezier patch with 3 bezier curves.

Post by emills2 »

I just wish someone had already coded up a three and five sided patch.
people have, but it's either proprietary software or journal articles that very challenging to implement.

This is what i'm working towards in my project. The ugly glob picture above shows an attempt with cubic bezier quads. I plan on using NURBS and maybe degree 5 or 6 eventually. To do so, i have to implement all the basic NURBS surface joining strategies first.

@yorik: NURBS/bezier curves don't 'want' quads, and there are triangular surface methods out there, but they aren't popular. What is popular, and what occ uses, is tensor product surfaces.
avtbtsgtrsgbr.PNG
avtbtsgtrsgbr.PNG (80.05 KiB) Viewed 2225 times
thereare two parametric dimensions, so the basic domain is a quadrilateral
pat_oneil
Posts: 36
Joined: Wed Jun 17, 2015 2:36 am

Re: bezier patch with 3 bezier curves.

Post by pat_oneil »

SECOND THOUGHTS:

Creating three quadrilateral beziers out of a triangle will not work well in FreeCAD since it cannot join two faces unless the edges are identical. Therefore I can not join a "triangle" edge with a standard bezier edge since the triangle edge has been split to create the quadrilateral.

The null solution seems to be working for me EXCEPT for when faces are fused, extruded and then cut an the exact point of the "null" curve. Don't think it will be a problem for me but limits the approach as a generalized solution.

Conclusion: There is no generalized answer in FreeCAD for 3 bezier curves.
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: bezier patch with 3 bezier curves.

Post by emills2 »

i don't have time right now to build a full example for a three-quad triangle, since it would be ugly anyway, but i must take exception to your claim FreeCAD can't handle split edges! (that last sentence should be read with a foppish accent while waving a white glove ;))
split edge shell boolean test - pass.png
split edge shell boolean test - pass.png (81.91 KiB) Viewed 2191 times

all curves and wavy surfaces built with the macros i linked earlier. flat faces built with shape builder (it's much much more than an inconvenient way to fuse things). faces > shell > solid all done in shape builder. standard Part cylinder. boolean difference works right smack across the the seam that has 1 surface on the bottom, but two on top.

I tell you man, it's the normals that are messing with you!

model included if you want to play around with it. warning, model tree is poorly organized.
Attachments
body test split edge.fcstd
(97.22 KiB) Downloaded 66 times
pat_oneil
Posts: 36
Joined: Wed Jun 17, 2015 2:36 am

Re: bezier patch with 3 bezier curves.

Post by pat_oneil »

Here is my simplified model, only 2 faces, fused and extruded . However, if you substract the cube from it, it will fail.
The face normals are correct. Face 5 is the problem face.....

Is it because I am using Bezier patches and you are using NURBS?
Attachments
Problem3Bezier2.FCStd
(14.98 KiB) Downloaded 46 times
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: bezier patch with 3 bezier curves.

Post by emills2 »

Your example model uses the "two edges colinear / corner disappears" method for making triangles. I'm sorry i can't help, because that method is a dead end for my purposes.

My model joins two SURFACES to a single SURFACE along one edge. I only brought it up because i misunderstood you.
You said
triangle will not work well in FreeCAD since it cannot join two faces unless the edges are identical
we don't mean the same thing in regards to
cannot join two faces unless the edges are identical
in my picture, i join a surface half way along an edge. half an edge is not identical to the whole edge. for me this qualifies, but i totally understand that for your case it doesn't.

My model only shows that the triangle/three-quadrangle scheme can work in FreeCAD.
[edit: in case this wasn't blindingly obvious, the picture below is not from FreeCAD, it's just an example of existing methods to deal with triangles in NURBS]
nurbs triangle by quads.png
nurbs triangle by quads.png (57.14 KiB) Viewed 2144 times
if the triangle is in red, the quad decomposition split each edge in 2, my method allows a single surface along each side the triangle instead of two as shown in the picture.

last minute addition. i re-extruded your collapsed corner triangle and tried a single boolean. it works ok. Unless you are willing to say how you split the edge, i can't help you join the two parts.
bad tri good boolean.png
bad tri good boolean.png (11.87 KiB) Viewed 2144 times
maybe the problem is the other triangle? how did you make it?
pat_oneil
Posts: 36
Joined: Wed Jun 17, 2015 2:36 am

Re: bezier patch with 3 bezier curves.

Post by pat_oneil »

Thanks for being so patient with me. I appreciate your time and effort.

I created the other triangle using the null curve approach. I do not think this particular face is the problem.

I see that you got the cube to "substract" from the fused, extruded faces. I have tried every combination I can think of and cannot get it to work. Exactly what steps did you do to make it work?
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: bezier patch with 3 bezier curves.

Post by emills2 »

it's not the fused object. it's only the 'flat corner' triangle. i just wanted to see if the 'flat corner' triangle was enough to mess up the boolean. i did not include the 'collpapsed edge' triangle. i was trying to prove you shouldn't align two edges to make a triangle. In the end, i proved that i was wrong, it's not as bad as i thought.

Honestly, at this point, i see two possibilities:

-extrude is not a good way to make these types of surfaces. the other option is to copy the surfaces, move them, then create caps for the missing sides, and use shape builder to make a shell and solid.

-maybe your curve split is causing a problem? you see in my earlier picture that it is possible in principle to have two edges along one. maybe yours is not accurate enough (i'm just looking for possible problems).

are you using the segment() function for bezier curves to get exact splits? maybe a De Casteljau trellis method?

Maybe you're right that FreeCAD can't handle it, but i think there's something we're missing. If FreeCAD can cut both types of triangles, i think it can handle the mix.
pat_oneil
Posts: 36
Joined: Wed Jun 17, 2015 2:36 am

Re: bezier patch with 3 bezier curves.

Post by pat_oneil »

I am splitting the curves in javascript using the following code: (Not sure where I got it from and do not fully understand the math)
splitCurve:function(bezier,t) {
var midpoints=function(pointList) {
var midpoint = function(p, q) {
return new THREE.Vector3(p.x+t*(q.x-p.x),p.y+t*(q.y-p.y),p.z+t*(q.z-p.z));
};
var midpointList = new Array(pointList.length - 1);
for (var i = 0; i < midpointList.length; i++) {
midpointList = midpoint(pointList, pointList[i+1]);
}
return midpointList;
}
var firstMidpoints = midpoints(bezier);
var secondMidpoints = midpoints(firstMidpoints);
var thirdMidpoints = midpoints(secondMidpoints);

return {left:[bezier[0], firstMidpoints[0], secondMidpoints[0], thirdMidpoints[0]],
right:[thirdMidpoints[0], secondMidpoints[1], firstMidpoints[2], bezier[3]]};
},
It seems to work since when I view wires and zoom in, they match exactly. However, I have been rounding all x,y,z to 3 decimal points in Javascript. Do you think that might be a problem? Should I, could I use a FreeCAD python function to split my curves? I am not familiar with doing these operations in FreeCAD.

I could get by without "substract" but need to be able to do "Fuses" and fuses also fail.
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: bezier patch with 3 bezier curves.

Post by emills2 »

If you're working outside of FreeCAD and python to generate your points, i can't help much.

Nevertheless, i think you put your finger on it already: 3 decimals? nowhere near enough.

You may be able to build faces as long as you use all the same points AFTER rounding off, but your midpoints are going to be too far off the curve as soon as the curves aren't completely flat and straight.

FreeCAD + python is a great tool for precise curve manipulation

in the console session below, the curve splitting happens in one line:

bz.segment(0,0.12345), where 0.12345 is 't' in your java.
>>> import Part
>>> bz=Part.BezierCurve()
>>> bz
<BezierCurve object>
>>> bz.getPoles()
[Vector (0.0, 0.0, 0.0), Vector (0.0, 0.0, 1.0)]
>>> # quadratic three point curve
>>> bz.FirstParameter
0.0
>>> bz.LastParameter
1.0
>>> bz.segment(0,0.12345)
>>> bz.getPoles()
[Vector (0.0, 0.0, 0.0), Vector (0.0, 0.0, 0.12345)]
>>>
and the Part.BezierCurve object has a .parameter() method that will return the 't' value for a nearby point if you wan tto pick it from the screen.
emills2
Posts: 875
Joined: Tue Apr 28, 2015 11:23 pm

Re: bezier patch with 3 bezier curves.

Post by emills2 »

btw, segment is only one of a treasure trove of functions FreeCAD has built in to deal with bezier curves.

bz.Construction
bz.Continuity
bz.Degree
bz.EndPoint
bz.FirstParameter
bz.LastParameter
bz.MaxDegree
bz.NbPoles
bz.StartPoint
bz.approximateBSpline
bz.discretize
bz.getPole
bz.getPoles <<<<<<< extract points to check that they match correctly
bz.getResolution
bz.getWeight
bz.getWeights
bz.increase
bz.insertPoleAfter
bz.insertPoleBefore
bz.intersect2d
bz.isClosed
bz.isPeriodic
bz.isRational
bz.length
bz.makeRuledSurface
bz.mirror
bz.parameter <<<<< get parameter near a point
bz.removePole
bz.scale
bz.segment <<<<<<< split the curve
bz.setPole
bz.setPoles <<<<<<<<<modify an existing curve
bz.setWeight
bz.tangent
bz.toBSpline
bz.toShape
bz.transform
bz.translate
bz.value <<<<< get position at a parameter



And the surfaces have similar functions! You should check them out.
Post Reply