I'm trying to create an animation of a complex path using HTML5 canvas. I've divided my path into some bezier curve and draw each one of them using the cubic bezier curves formula and javascript function lineTo(). The problem is the points that the curves connected to each other. They're not connecting smoothly. I've realized that this problem will be solved if I use the B-Spline curve instead of bezier curves. So, I'm wondering if there is any method to convert bezier curves to b-spline?
Theoretically, a Bezier curve can be considered as a single segment B-spline curve. So, there is really no such thing as "converting a Bezier curve to a B-spline curve". If you can implement cubic Bezier curve evaluation function according to the info in the Wikipedia page, it should not be difficult to implement B-spline curves according to the De Boor algorithm.
If you do not want to go with the extra length of implementing B-spline curves, then what you can do is to modify the Bezier curve's control points locally to make them smoothly joined together. Assuming you have two cubic Bezier curve C1(t) defined by P0,P1,P2 and P3 and C2(t) defined by Q0, Q1, Q2 and Q3 with P3=Q0. You can make C1(t) and C2(t) joined smoothly by projecting P2 and Q1 on a line passing thru the common point P3. How do you choose the line's direction is up to you.
Related
When you enter the Bézier curve feature of software like Microsoft Office, LibreOffice, and Blender, they let you create and juxtapose cubic, aka fourth-order, aka 4-control-point, Bézier curves. You click-and-drag creating the two points P0 and P3 and interpolate them, and the last two control points of the convex hull P1 and P2, that are not on the curve, are usually hidden or displayed as handles.
Why this focus on cubic (4 points) over quadratic (3 points), quintic (5 points), and higher-order curves?
Why is it considered uninteresting to lower or elevate the curve order?
When you complicate your curve design you usually join cubic Bézier curves together: this is what happens when you click repeatedly to add points, or subdivide. Why is so little software allowing you to define all your N control points at once, and then interpolate those with a Nth-order Bézier curve? This would be a constraint-based approach in opposition to the traditional "editing" approach (not sure how to word it).
Quadratic béziers allow curves to be joined so they share a tangent line. But they won't share the curvature. With unequal curvature, highlights and mirror effects will show an ugly discontinuity. The curvature is even more important when the curve is used to control a camera path or a robot trajectory. Cubic béziers can solve that.
Note that quadratic béziers are used in computer graphics, especially in the early days when calculation speed was more limited. For example TrueType fonts and Adobe Flash (the animation package that powered many websites until about a decade ago) depend on quadratic béziers.
Quartic curves are defined by 5 points; the curve will go through the end points, and its derivatives will be controlled by 3 more points. With cubic curves, one quickly gets an intuitive feeling of the function of the two controlling points; with a quartic the exact consequence of moving one of the inner control points is harder to guess. And when even more points would be involved, deformations would even be harder to control. Also, the computational cost goes up for curves involving more points.
These deformations are also the main reason why one doesn't use fully interpolating curves. Between the control points, undesired bends are hard to avoid.
PS: Did you check out "The Beauty of Bézier Curves"? For example, starting at 6:18, derivatives are explained. 9:07 deals with the curvature.
Probably the reason number one to join cubic splines (or low degree splines in general) is to maintain "locality" of control points i.e., moving a single control point only affects one segment of the curve or two at most if it is the joint point. That locality property is highly desirable on modeling applications. On the other hand high degree curves gives a more "global" effect to each control point.
I believe the cubic spline in particular gives the best compromise between locality and flexibility of the curve sice it can provide C^2 continuity when joining segments. The quadratic spline is also useful and valuable tool for the right problem but it only provides C^1 continuity when joining the segments, which can be a limitation for complex modeling applications.
How do I compute the control points given a curve in the form of power form? Say I have p(t)=(x(t),y(t)) and 4 control points.
x(t) = 2t
y(t) = (t^3)+3(t^2)
You can always convert from power basis to Bernstein basis. This is always doable and will give you the precise result. Refer to section 3.3 of this link (http://cagd.cs.byu.edu/~557/text/ch3.pdf) for details.
EDIT:
Since the above link is no longer available, I am listing the formula below:
where M is the degree of the Berstein basis, 0 <= k <= M and b_i,k=0 if i < k.
Using the common cubic Berstein basis (where M=3) as an example, we will have
this is pure math question (unless you go for the #3)... I am deducing you need 4 control points for single cubic Bezier curve in 2D.
algebraic approach
try to match your x(t),y(t) polynomials to Bezier polynomials form and extract the coefficients/control points. This is not always doable but most precise... see the link in #2 at the end I do this for my interpolation polynomial to match the Bezier so I get the conversion formula between control points.
interpolation
find extreme points on your curve (to preserve precision as much as possible) if none or not enough extremes found use equally dispersed points along curve for the rest. You need 4 control points on the curve. Now just convert these 4 points to curve for example by this: how to convert interpolation cubic polynmial to cubic Bezier
can use curve fitting
either use approximation search or any other minimization of curves distance ... by fitting Bezier control points but that is 8 parameters to search for which is slow and non precise without additional constrains ..
I am sure there are a lot more (possibly hybrid) methods out there for this problem.
I am developing a 3D graphic application in which the user can draw curves.
I record the curve that is drawn by the user and i would like to create a smooth nurb from the recorded set of points.
I tried using the openNurbs library but i could not find a way to do the fitting using the library.
How can i fit a set of points to a nurb?
First of all, I don't think you need nurbs. Fitting a B-spline curve to your data points should be good enough.
If you only have a few dozen points, then it is likely you would like the B-spline curve to exactly pass thru these data points. In this case, you are looking for spline interpolation algorithms. If this is the case, you can use Catmull Rom spline or Overhauser spline to interpolate your data points. Both will create C1 cubic splines and both are easy to implement without the need to solve a linear equation set.
If you have several hundreds of points, then it is likely that you only want the B-spline curve to lie close to the data points. Then, the algorithm you are looking for is least square fitting. You can find plenty of articles (e.g.: link1 ) in this area online. A typical algorithm for least square fitting with B-spline curve will involve these steps:
1) Choose a parametrization for your data points. Chord length parametrization is typically a good choice for least square fitting.
2) Choose the degree for the B-spline. Typically, we use degree 3, i.e., cubic B-spline.
3) Decide number of control points for your B-spline.
4) Decide the knot vector based on the information in the first 3 steps.
5) Solve a linear equation set to find the control points of the B-spline.
I am wondering if the number of control points will always be 2 more than the number of fit points.
Specially for cubic spline.
Based on your question, I would guess that you're either asking about natural cubic spline curves, or Bezier spline made from cubic Bezier curves. In the case of natural cubic spline curves, the number of control points is exactly the same as the number of fit points.
However, I'm pretty sure you're actually talking about Bezier splines. It's a little trickier here. If you just want a single cubic Bezier curve, then you are correct that 2 fit points (the end points) are needed, as well as two more control points. But if we add a second Bezier curve to form a Bezier spline, we need one more fit point plus another two control points. That's a total of 7 control points, 3 of which are fit points. Adding a third curve gives 10 control points, of which 4 are fit points. If we continue adding curves like this, we can see that the number of control points is actually 3*n-2, where n is the number of fit points.
Is it possible to calculate intermediate points of a curve...Here is my mirror image
In the above image.Is it possible to calculate the intermediate points(one side) by knowing starting and ending point
If you know something about the curve it is, and it all depends on what you know about the curve (start and end points, initial slopes, center points, etc). There are generally two approaches:
If you know the equation of the curve, it's possible to do this exactly. Commonly curves like this are either circles or Bezier curves, and if you know it's either of these, you can fit all the other points exactly just given a few.
You can also do a cubic spline fit. This is a standard approach to fitting smooth curves so packages to do this are very common. On a smooth curve like this, give then end points, and, say, the middle point, the fit will be almost exact. (Here, you essentially end up with a Bezier curve, though parametrized a bit differently.)