Preliminary study on Bezier curve

Source: Internet
Author: User
Tags polyline

The following turns

Bezier curve, you can use three points to determine a smooth curve. In computer graphics there should be talk. is an important tool in the development of graphics.

The realization is a graph to do circular motion. However, it is not a simple keyframe animation, it is to calculate a lot of points, of course, or use the Keyframe animation, that is, using cakeyframeanimation. With Bezier support, you can assign a path reference to a cakeyframeanimation Bezier curve.

Drawing a circle with a Bezier curve is a special case, and my approach is to get 4 semi-circular curves with Bezier curves, which are the entire circle.

The following is the code for the animation section:

-(void) doanimation {
cakeyframeanimation *animation=[cakeyframeanimation animationwithkeypath:@ "position"];
animation.duration=10.5f;
animation.removedoncompletion = NO;
animation.fillmode = kcafillmodeforwards;
animation.repeatcount=huge_valf;//Repeat Forever
Animation.calculationmode = kcaanimationcubicpaced;

cgmutablepathref curvedpath = cgpathcreatemutable ();
cgpathmovetopoint (Curvedpath, NULL, 184);

Animation.path=curvedpath;

}

Bézier curve ( Bezier curve ) is a mathematical curve applied to a two-dimensional graphical application. Curve definition: Start point, end point (also called Anchor Point), control point. By adjusting the control point, the shape of the Bezier curve changes. In 1962, Pierre Bézier , the French mathematician, first studied the method of the vector drawing curve and gave a detailed calculation formula, so the curve drawn by such a formula is named after his surname, called the Bezier curve.

In the following formula: B (t) is the coordinate of the point at t time;

P0 is the starting point, PN is the end point, Pi is the control point

first-order Bezier curves (line segments):

Meaning: A line segment described by a continuous point from P0 to P1

Principle: A continuous point Q0 from P0 to P1, describing a line segment.
A continuous point Q1 from P1 to P2 that describes a line segment.
A continuous point B (t) from Q0 to Q1 that describes a two-time Bezier curve.

Experience: P1-p0 is the tangent of the curve at P0.

Sanche Besel curve:

General formula:

Gauche Besel curve:

4-Step curve:

5-Step curve:

Http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/de-casteljau.html

Following the construction of a Bézier curve, the next important task is to find the point C(U) on the curve for a particular U. A simple-to-plug u into every basis function, compute the product's basis function and its corresponding cont Rol point, and finally add them together. While this works fine, it's not numerically stable (i.e., could introduce numerical errors during the course of Evaluatin G the Bernstein polynomials).

In what follows, we shall only write down the control point numbers. That is, the control points are  xx  for  P 0,  01  for  P 1, ...,   0i  for  P I, ...,   0n  for  P N. the  0 s in these numbers indicate the initial or the 0-th iteration. Later on, it'll be replaced with  1 ,   2 ,   3   And so on.

The fundamental concept of de Casteljau ' s algorithm is to choose a point C on line segment AB such that C divides the line segment AB in a ratio of u:1-u (i.e., the ratio of the distance between a D C and the distance between A and B is u). Let us find a by-determine the point C.

The vector from  A  to  B  is  b-a . Since u is a ratio in the range of 0 and 1, point  C  is located at u ( B- A ). Taking the position of  a  into consideration, point  C  is  a  + u ( b-a ) = (1- u) A  +  u B . Therefore, given A u, (1- u) a  + u B  is the point  C  between  A  and  B  that divides   AB  in a ratio of u:1-u.

The idea of de Casteljau ' s algorithm goes as follows. Suppose we want to find C(u), where u are in [0,1]. Starting with the first polyline, 00-01-02-03...-0n, use the above formula to find a point 1i on the leg (i.e. line segment) from 0i to0 (i+1), divides the line segment 0i and 0 (i+1) in a Ratio of u:1-u. In this, we'll obtain n points, one, ten, ...., 1 (n-1). They define a new polyline of n-1 legs.

In the Above, u is 0.4. ,  is in the leg of  xx &NBSP;AND&NBSP, ,  , one  is in the leg of    and  , ..., and   and  is in the leg of all   . All of these new points is in blue.

The new points is numbered as 1iS. Apply the procedure to this new polyline and we shall get a second polyline of n-1 points , 2 (n-2) and n-2 legs. Starting with this polyline, we can construct a third one of the n-2 points, 3 (n-3) an D n-3 Legs. Repeating this process n times yields a single point n0. De Casteljau proved that's the point C(U) on the curve, which corresponds to U.

Let us continue and the above figure. Let -Being the point in the leg ofTenand OneThat's divides the line segmentTenand OneIn a ratio of u:1-u. Similarly, choose +On the leg of Oneand A, AOn the leg of Aand -, and atOn the leg of -and -. This gives a third polyline defined by -, +, Aand at. This third polyline have 4 points and 3 legs. Keep doing this and we shall obtain a new polyline of three points -, toand +. From this fourth polyline, we have the fifth one of the points +and A. Do it once more, and we have -, the pointC(0.4) on the curve.

This is the geometric interpretation of de Casteljau's algorithm, one of the most elegant result in curve design.

Actual Computation Given the above geometric interpretation of de Casteljau ' s algorithm, we shall present a computation method, which is show N in the following.

First, all given control points was arranged into a column, which was the left-most one in the. For each pair of adjacent control points, draw a south-east bound arrow and a north-east bound arrow, and write down a new Point at the intersection of the adjacent arrows. For example, if the-adjacent points is ij and i (j+1), the new point is(i+1) J. The South-east (resp., north-east) bound arrow means multiplying 1-u (resp., u) to the point at its tail, ij(re Sp., I (j+1)), and the new point is the sum.

Thus, from the initial column, column  0 , we compute column  1 ; from column   1  we obtain column  2  and so on. Eventually, Aftern applications we shall arrive at a single point  n0  and On the curve. The following algorithm summarizes we have discussed. It takes an array  P  of n+1 points and a u in the range of 0 and 1, and returns a Point on the Bézier curve  C (u).

Q [i]:=  p [i];//save input
Q [i]: = (1-  u) q [i] +  u   q [i  + 1]; for  i := 0 , to  n-k , do   Input:  array  P [0:n] of n+1 points and real number u in [0,1] &NBSP
Output:  point on curve,  C (u)
working:  point array  Q [0:n]

for  i := 0  to  n , do
for
k := 1 , to  n  do
Return q
[0];

A Recurrence Relation The above computation can be expressed recursively. Initially, let P 0,j is p J for j = 0, 1, ..., N. That is, P 0,j are the j-th entry on column 0. The computation of Entry J on column I is the following:

More precisely, entry pi,j is the sum of (1-u)Pi-1,j (upper-left corner) and uPi-1,j+1 (lower-l EFT corner). The final result (i.e, the point in the curve) is Pn,0. Based on the "idea", one may immediately come up with the following recursive procedure:

return P0,j
return (1-u) * Decasteljau (I-1, j) + U * decasteljau (i-1, J + 1) if i = 0 Then
else
function decasteljau(i,j)
Begin
End

This procedure looks simple and short; However, it is extremely inefficient. Here's why. We start with a call toDecasteljau(n,0) for computing Pn,0. The else part splits this call into the and the calls, Decasteljau(n-1,0) for computing Pn-1 , 0 and Decasteljau(n-1,1) for computing Pn-1,1.

Consider the call toDecasteljau(n-1,0). It splits into the more calls,Decasteljau(n-2,0) for computingPn-2,0 andDecasteljau(n-2,1) for computingPn-2,1. The call toDecasteljau(n-1,1) splits into and calls,Decasteljau(n-2,1) for computingPn-2,1 andDecasteljau(n-2,2) for computingPn-2,2. Thus,Decasteljau(n-2,1) is called twice. If We keep expanding these function calls, we should discover that almost all function calls for computingPI,j is repeated, not once but many times. What is the This? In fact, the above computation scheme was identical to the following-in-A-Z of computing then-th Fibonacci number:return1
returnFibonacci(n-1) +Fibonacci(n-2)ifn = 0orn = 1Then
else
functionFibonacci(n)
BeginendThis program takes a exponential number of function calls (an exercise) to computeFibonacci(n). Therefore, the above recursive version of De Casteljau ' s algorithm is notSuitable for direct implementation, although it looks-simple and elegant!

An interesting observation

The triangular computation scheme of de Casteljau ' s algorithm offers an interesting observation. Take a look at the following computation in a Bézier curve of degree 7 defined by 8 control points xx, 01, ..., the. Let us consider a set of consecutive points on the same column as the control points of a Bézier curve. Then, given a u in [0,1], how does we compute the corresponding point to this Bézier curve? If de Casteljau ' s algorithm is applied-these control points, the point on the curve is the opposite vertex of the Equil Ateral ' s base formed by the selected points!

For example, if the selected points are  ,   ,   04  and  , the point on the curve defined by these four control points that corresponds to u is  . See the Blue Triangle. If the selected points are  one ,    and  + , The point on the curve is to . See the Yellow triangle. If the selected points are  ,   to ,   +  and  the point is on the curve is  + .

By the same reason, the "the point" on the Bézier curve defined by control points. It is also the-the-curve defined by , Wuyi and curve defined by 40< /c6>, A. In general, if we select a point and draw an equilateral as shown above, the base of this equilateral consists of the Cont Rol points from which, the selected point is computed.

Reference: http://my.oschina.net/u/223340/blog/326947

Http://blog.chinaunix.net/uid-20622737-id-3161025.html

Http://www.cnblogs.com/jay-dong/archive/2012/09/26/2704188.html

http://blog.csdn.net/eclipsexys/article/details/51956908

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.