We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Actually, the bezier() can only do 2 control points an 1 start,end point. But, I want to do a Bezier curve with 7 control points or more/less. How can I do ? bezierVertex(), quadraticVertex() do not make what I want.
Answers
@Mxw309 --
If you want a Bezier curve with 7 control points, then bezierVertex() does make what you want.
See the Processing Curves Tutorial section "Continuous Bézier Curves":
Example:
Alternately you can specify a continuous spline curve with no control points at all (but lots of spline points) using
curve()
/curveVertex()
.do you want linked cubic beziers or one bezier with 7 control points (an 8th order curve) though?
latter is possible, but it gets crazy quickly
so instead of the following (3rd order equation, image from wikipedia)
you'd have
where t goes from 0 to 1 and P0 is start, P8 is the end, P1 to P7 are the 7 control points
(the 8, 28, 56 etc come from the lines of Pascal's Triangle - https://en.wikipedia.org/wiki/Pascal's_triangle)
Do you mean higher order Bezier curve as shown here in Wikipedia
@jeremydouglass It's doing good for some shape, but, there is a problem. I want to make a shape like a loop, and the anchor points created are problematic. Exemple (white circle : control points, red circle : anchor points) :
@koogs I would test this, but I have no idea how to create a curve with this :/
@quark Yes
@koogs It's crazy but it works
@Mxw309 -- as I quoted before:
See how a straight line between the two white dots doesn't have the red dot in between them? That is why the curve is broken.
Also, your loop is defined with 4 points (3 segments) -- you might want to try 6 points (5 segments) for more control.
BTW -- I believe that koogs approach and the simple-sectional approach are equivalent, by De Casteljau's algorithm. See the Example Implementation and Geometric Interpretation. Essentially, you can split higher degree Bézier curves into several lower degree Bézier curves. The control points are expressed differently, but the curve is the same.
That said, @koogs solution is very cool. It would be nice to fancy it up by implementing it as a function that takes any degree, and then rendering line segments from an array rather than points (or even storing the point data as vertices in a PShape).
One last find:
On the Math.Stackexchange thread Casteljau's algorithm - practical example, Chris Taylor shared a Java class
Casteljau
for solving a high degree Bézier curve by interpolating n points between a collection of Bézier section points for a curve of any degree. Eyeballing it, I think this might be the approach of @koogs seven-degree demo approach written as a class.Feed the resulting point array back into a simple spline curve / PShape to get a continuous rendering.
Yeah, apologies, that was just thrown together in 30 minutes using stuff dragged out of my memory from my 1989 degree course... 8)
A proper solution would, yes, let you define the degree and number of points and join them up.
To get a c2 continuous bezier curve the control points either side of one of the intermediate start / end points have to be collinear AND of equal length. You end up with an odd mix of points that are passed through and points that affect the curve doing it this way though, which I always find a bit odd. That said, anything above a cubic always seems a bit odd to me anyway.
(Will draw a picture when I'm on laptop)
ok, quick sketch
see the curve around the join in the first part isn't smooth but the second one is? there's no sudden change in direction because the control points around the mid point are in a line but there IS a sudden change in the speed in which the curve changes. in the second one it's smoother because the control points are opposite AND at the same distance.
What is being discussed here is a Bezier spline NOT a high order Bezier curve.
Bezier spline - a smooth curve that passes through three or more fixed (anchor) points. The fixed points are connected by cubic (mostly) Bezier curves. These are the ones you normally see in vector graphic packages. A cubic Bezier curve has four controls points, 2 fixed representing the ends and 2 that define the curve shape.
A high order Bezier is a single curve that has
n
controls points, wheren > 4
. As before 2 control points define the start and the end of the curve and the othern-2
points control the shape.The Shapes3D library has a number of classes you could use or hack to meet your needs
Bezier2D for a single Bezier curve of any degree >= 2 in 2D
P_Bezier3D same but for 3D
P_BezierSpline a smmoth curve that passes through any number of anchor points linked by cubic Bezier curves.
Note in your picture above you have 3 Bezier curves, 2 which are cubic (order 4) and the third that links the lower two red points is a quadratic (order 3)
we are talking both, i think, because it's not clear which the OP requires.
I asked the question in my first comment and the OP agreed he was interested in higher order Bezier curves but then then immediately posted a picture of a Bezier spline. Obviously the OP is confused regarding the difference between high-order and spline hence my last comment.
I suspect that what he really needs is a Bezier spline because it is much easier to control the overall shape of the curve.
This discussion gives an example of using the Shapes3D library to create a Bezier spline.
@quark @koogs Yes, I think i'm confused between high-order and spline. But the picture that I posted was to demonstrate that bezierVertex() doesn't make what I want (because it create Bezier spline ?). The koogs code make what I want actually (because it create high-order bezier ?). It's why I guess i'm researching high-order bezier. This is what koogs code make, and this is actually what I want
Actually I'm trying to use the 3DShapes to make 2DBezier, because it seem to be shorter and easier to use... but how to make and draw a 2DBezier is confusing me.
woo!
what jeremy said about being able to decompose beziers into multiple lower order beziers suggests that it'd be possible to write everything in terms of quadratic beziers. but you'd need quite a few. i can't remember ever being told this but it was a long time ago. (we did the maths behind the splines, joining them and then 3d patches, all stuff i still use occasionally)
i've never used 3dshapes library(1) but it looks like it has a lot of things that i was just about to write my own library for (textured cubes not the least of it). will have to investigate.
(1) i tend to avoid libraries because most of what i do is an attempt to work out for myself how to do geometrical things. also they get outdated.
can you post your control point coords so we can emulate?
Of course :
Although you can decompose high degree to a number of lesser degree Bezier curves this still requires you to calculate new anchor points on the original curve. It is also possible and more common to increase the degree and still retain the original shape. This can be done mathematically
The code below uses the Shapes3D library and your control points to produce this picture.
@quark Damn, that was easier than I thought. I'll use this so. @all Thanks a lot for your helps, you free me !