Bài giảng Đường cong trong không gian 3D curve

Why use curves? Quỹ đạo chuyển động của 1 điểm trong không gian „ Đường cong biểu diễn Điểm-curve represents points: „ Điểm Biểu diễn và kiểm soát đường cong -Points represent-and control-the curve. „ Cách tiếp cận này là cơ sở của lĩnh vực Computer Aided Geometric Design (CAGD)

pdf11 trang | Chia sẻ: haohao89 | Lượt xem: 2152 | Lượt tải: 2download
Bạn đang xem nội dung tài liệu Bài giảng Đường cong trong không gian 3D curve, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 1 (c) SE/FIT/HUT 2002 Đường cong trong không gian 3D CURVE (c) SE/FIT/HUT 2002 2 Đường cong - Curve „ Why use curves? Quỹ đạo chuyển động của 1 điểm trong không gian „ Đường cong biểu diễn Điểm -curve represents points: „ Điểm Biểu diễnvà kiểm soát đường cong -Points represent- and control-the curve. „ Cách tiếp cận này là cơ sở của lĩnh vực Computer Aided Geometric Design (CAGD). (c) SE/FIT/HUT 2002 3 Phân loại „ Trên cơ sở ràng buộc giữa điểm và đường trong cả ứng dụng khoa học và thiết kế ta co thể phân làm 2 loại: „ Xấp xỉ-Approximation - „ Được ứng dụng trong mô hình hoá hình học „ Nội suy-Interpolation „ Trong thiết kế nôi suy là cần thiết với các đối tượng nhưng không phù hợp với các đối tượng có hình dáng bất kỳ "free form“. (c) SE/FIT/HUT 2002 4 Biểu diễn Đường cong „ Tường minh y=f(x) „ y = f(x), z = g(x) „ impossible to get multiple values for a single x • break curves like circles and ellipses into segments „ not invariant with rotation • rotation might require further segment breaking „ problem with curves with vertical tangents • infinite slope is difficult to represent „ Không tường minh f(x,y)=0 - Implicit equations: „ f(x,y,z) = 0 „ equation may have more solutions than we want • circle: x² + y² = 1, half circle: ? „ problem to join curve segments together • difficult to determine if their tangent directions agree at their joint point (c) SE/FIT/HUT 2002 5 Đường cong tham biến „ Biểu diễn các đường cong tham biến Parametric representation: „ x = x(t), y = y(t), z = z(t) „ overcomes problems with explicit and implicit forms „ no geometric slopes (which may be infinite) „ parametric tangent vectors instead (never infinite) „ a curve is approximated by a piecewise polynomial curve „ Define a parameter space „ 1D for curves „ 2D for surfaces „ Define a mapping from parameter space to 3D points „ A function that takes parameter values and gives back 3D points „ The result is a parametric curve or surface 0 t1 Mapping F :t → (x, y, z) (c) SE/FIT/HUT 2002 6 Parametric Curves „ We have seen the parametric form for a line: „ Note that x, y and z are each given by an equation that involves: „ The parameter t „ Some user specified control points, x0 and x1 „ This is an example of a parametric curve 10 10 10 )1( )1( )1( zttzz yttyy xttxx −+= −+= −+= CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 2 (c) SE/FIT/HUT 2002 7 Đường cong đa thức bậc ba „ Phải đảm bảo là đường cong không gian với 3 trục toạ độ x, y, z „ tránh được những tính toán phức tạp và những phần nhấp nhô ngoài ý muốn xuất hiện ở những đường đa thức bậc cao „ Why cubic? (c) SE/FIT/HUT 2002 8 P0 P1 p2 p3 P0 P'0 P1 P'1 Đường cong bậc 3 „ x = a1 + b1u + c1u2 + d1u3 „ y = a2 + b2u + c2u2 + d2u3 „ z = a3 + b3u + c3u2 + d3u3 „ Với 3 điểm P0, P1, P2, P3 phương trình xác định (c) SE/FIT/HUT 2002 9 Hermite Spline „ A spline is a parametric curve defined by control points „ The term spline dates from engineering drawing, where a spline was a piece of flexible wood used to draw smooth curves „ The control points are adjusted by the user to control the shape of the curve „ Phương pháp Hermite dựa trên cơ sở của cách biểu diễn Ferguson hay Coons năm 60 „ A Hermite spline is a curve for which the user provides: „ The endpoints of the curve „ The parametric derivatives of the curve at the endpoints • The parametric derivatives are dx/dt, dy/dt, dz/dt „ That is enough to define a cubic Hermite spline, more derivatives are required for higher order curves (c) SE/FIT/HUT 2002 10 Đường cong Hermite „ p = p(u) = k0 + k1u + k2u2 + k3u3 „ p(u) = ∑kiui i∈n „ p0 và p1 ta có hai độ dốc p0’ và p1’ với u = 0 và u = 1 tại hai điểm đầu cuối của đoạn [0,1]. „ We have constraints: „ The curve must pass through p0 when u=0 „ The derivative must be p’0 when u=0 „ The curve must pass through p1 when u=1 „ The derivative must be p’1 when u=1 (c) SE/FIT/HUT 2002 11 Basis Functions „ A point on a Hermite curve is obtained by multiplying each control point by some function and summing „ The functions are called basis functions (c) SE/FIT/HUT 2002 12 „ Thay vào: „ p = p(u) = p0(1-3u2+2u3) + p1(3u2-2u3) + p0’(u-2u2+u3) + p1’(-u2+u3) p = p(u) = [ 1 u u2 u3 ] CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 3 (c) SE/FIT/HUT 2002 13 Đường cong Bezier „ Sử dụng điểm và các vector kiểm soát được độ dốc của đường cong tại nhưng điểm mà nó đi qua.(Hermit) „ không được thuận lợi cho việc thiết kế tương tác, không tiếp cận vào các độ dốc của đường cong bằng các giá trị số (Hermite). „ Paul Bezier, RENAULT, 1970 đường và bề mặt UNISURF (c) SE/FIT/HUT 2002 14 „ po, p3 tương đương với p0, p1 trên đường Hermite. diểm trung gian p1, p2 được xác định bằng 1/3 theo độ dài của vector tiếp tuyến tại điểm po và p3 „ p0’ = 3(p1 – p0) „ p3’ = 3(p3 – p2) „ p = p(u) = p0(1-3u2+2u3) + p1(3u2-2u3) + p0’(u-2u2+u3) + p1’(- u2 + u3) „ p = p(u) = p0(1 - 3u + 3u2 - u3) + p1(3u-6u2-3u3) + p2(3u2 - 3u3) + p3u3 (c) SE/FIT/HUT 2002 15 Biểu diễn Ma trận p = p(u) = [ 1 u u2 u3 ]                 −− − − 3 2 1 0 1331 0363 0033 0001 p p p p 0 0.2 0.4 0.6 0.8 1 1.2 B0 B1 B2 B3 (c) SE/FIT/HUT 2002 16 Ưu điểm „ dễ dàng kiểm soát hi`nh dạng của đường cong hơn vector tiếp tuyến tại p0’ và p1’ của Hermite. „ Nằm trong đa giác kiểm soát với số điểm trung gian tuỳ ý( số bậc tuỳ ý) „ đi qua điểm đầu và điểm cuối của đa giác kiểm soát, tiếp xúc với cặp hai vector của đầu cuối đó (c) SE/FIT/HUT 2002 17 Example Bezier Curves „ [UW] (c) SE/FIT/HUT 2002 18 Sub-Dividing Bezier Curves P0 P1 P2 P3 M01 M12 M23 M012 M123 M0123 CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 4 (c) SE/FIT/HUT 2002 19 Sub-Dividing Bezier Curves P0 P1 P2 P3 (c) SE/FIT/HUT 2002 20 Sub-Dividing Bezier Curves „ Step 1: Find the midpoints of the lines joining the original control vertices. Call them M01, M12, M23 „ Step 2: Find the midpoints of the lines joining M01, M12 and M12, M23. Call them M012, M123 „ Step 3: Find the midpoint of the line joining M012, M123. Call it M0123 „ The curve with control points P0, M01, M012 and M0123 exactly follows the original curve from the point with t=0 to the point with t=0.5 „ The curve with control points M0123 , M123 , M23 and P3 exactly follows the original curve from the point with t=0.5 to the point with t=1 (c) SE/FIT/HUT 2002 21 de Casteljau’s Algorithm „ You can find the point on a Bezier curve for any parameter value t with a similar algorithm „ Say you want t=0.25, instead of taking midpoints take points 0.25 of the way P0 P1 P2 P3 M01 M12 M23 t=0.25 (c) SE/FIT/HUT 2002 22 Biểu thức Bezier-Bernstain „ Tổng quát hoá với n +1 điểm kiểm soát „ p0 ... pn : vector vị trí của đa giác n+1 đỉnh ))(()( )()( 1 0 1, 0 , ii n i ni i n i ni PpuBnup puBup −=′ = + = − = ∑ ∑ ini ni uuinCuB −−= )1(),()(, )!in(!i !n )i,n(C −= (c) SE/FIT/HUT 2002 23 Tính chất „ P0 và Pn nằm trên đường cong. „ Đường cong liên tục và có đạo hàm liên tục tất cả các bậc „ Tiếp tuyến của đường cong tại điểm P0 là đường P0P1 và tại Pn là đường Pn-1Pn . „ Đường cong nằm trong đường bao lồi convex hull của các điểm kiểm soát. „ This is because each successive Pi(j) is a convex combination of the points Pi(j-1) and Pi-1(j-1) . „ P1 ,P2 , … ,Pn-1 nằm trên đường cong khi và chỉ khi đường cong là đoạn thẳng. (c) SE/FIT/HUT 2002 24 Review: Bézier Curve Prop’s [1/6] „ We looked at some properties of Bézier curves. „ Generally “Good” Properties „ Endpoint Interpolation „ Smooth Joining „ Affine Invariance „ Convex-Hull Property „ Generally “Bad” Properties „ Not Interpolating „ No Local Control CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 5 (c) SE/FIT/HUT 2002 25 Problem with Bezier Curves „ To make a long continuous curve with Bezier segments requires using many segments „ Maintaining continuity requires constraints on the control point positions „ The user cannot arbitrarily move control vertices and automatically maintain continuity „ The constraints must be explicitly maintained „ It is not intuitive to have control points that are not free (c) SE/FIT/HUT 2002 26 Invariance „ Translational invariance means that translating the control points and then evaluating the curve is the same as evaluating and then translating the curve „ Rotational invariance means that rotating the control points and then evaluating the curve is the same as evaluating and then rotating the curve „ These properties are essential for parametric curves used in graphics „ It is easy to prove that Bezier curves, Hermite curves and everything else we will study are translation and rotation invariant „ Some forms of curves, rational splines, are also perspective invariant „ Can do perspective transform of control points and then evaluate the curve (c) SE/FIT/HUT 2002 27 Longer Curves „ A single cubic Bezier or Hermite curve can only capture a small class of curves „ At most 2 inflection points „ One solution is to raise the degree „ Allows more control, at the expense of more control points and higher degree polynomials „ Control is not local, one control point influences entire curve „ Alternate, most common solution is to join pieces of cubic curve together into piecewise cubic curves „ Total curve can be broken into pieces, each of which is cubic „ Local control: Each control point only influences a limited part of the curve „ Interaction and design is much easier (c) SE/FIT/HUT 2002 28 Piecewise Bezier Curve “knot” P0,0 P0,1 P0,2 P0,3 P1,0 P1,1 P1,2 P1,3 (c) SE/FIT/HUT 2002 29 Continuity „ When two curves are joined, we typically want some degree of continuity across the boundary (the knot) „ C0, “C-zero”, point-wise continuous, curves share the same point where they join „ C1, “C-one”, continuous derivatives, curves share the same parametric derivatives where they join „ C2, “C-two”, continuous second derivatives, curves share the same parametric second derivatives where they join „ Higher orders possible „ Question: How do we ensure that two Hermite curves are C1 across a knot? „ Question: How do we ensure that two Bezier curves are C0, or C1, or C2 across a knot? (c) SE/FIT/HUT 2002 30 Đường bậc ba Spline „ Spline đi qua n điểm cho trước mà mỗi đoạn là đường bậc ba độc lập có độ dốc và độ cong liên tục tại mỗi điểm kiểm soát hay điểm nút „ Với n điểm:n-1 đoạn với mỗi đoạn 4 vector hệ số 4(n-1) cho n-1 đoạn, và 2(n-1) điều kiện biên và n-2 điều kiện về độ dốc cùng n-2 về độ cong „ Spline dùng để chỉ phương pháp biểu diễn đường cong mềm thông qua các đoạn cong tham biến bậc ba với các điều kiện liên tục tại các điểm đầu nút CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 6 (c) SE/FIT/HUT 2002 31 Đường cong bậc ba Spline „ u0 = 0 với : (u0 ... un-1) uj+1 > uj „ ui+1 = ui + di+1 „ C0 để không có sự gián đoạn giữa hai đoạn cong. „ C1 tính liên tục bậc nhất hay đạo hàm bậc nhất tại điểm nối. „ C2 đạo hàm bậc hai liên tục của đường cong tại điểm nối (c) SE/FIT/HUT 2002 32 Achieving Continuity „ For Hermite curves, the user specifies the derivatives, so C1 is achieved simply by sharing points and derivatives across the knot „ For Bezier curves: „ They interpolate their endpoints, so C0 is achieved by sharing control points „ The parametric derivative is a constant multiple of the vector joining the first/last 2 control points „ So C1 is achieved by setting P0,3=P1,0=J, and making P0,2 and J and P1,1 collinear, with J-P0,2=P1,1-J „ C2 comes from further constraints on P0,1 and P1,2 (c) SE/FIT/HUT 2002 33 Bezier Continuity P0,0 P0,1 P0,2 J P1,1 P1,2 P1,3 Disclaimer: PowerPoint curves are not Bezier curves, they are interpolating piecewise quadratic curves! This diagram is an approximation. (c) SE/FIT/HUT 2002 34 B-splines „ B-splines automatically take care of continuity, with exactly one control vertex per curve segment „ Many types of B-splines: degree may be different (linear, quadratic, cubic,…) and they may be uniform or non-uniform „ We will only look closely at uniform B-splines „ With uniform B-splines, continuity is always one degree lower than the degree of each curve piece „ Linear B-splines have C0 continuity, cubic have C2, etc (c) SE/FIT/HUT 2002 35 Đường cong B-spline „ Đường cong B-spline là đường cong được sinh ra từ đa giác kiểm soát mà bậc của nó không phụ thuộc vào số đỉnh của đa giác kiểm soát. (c) SE/FIT/HUT 2002 36 B-Splines: The Idea [1/2] „ The repeated-lirping idea that produced the Bézier curves has the drawbacks that is produces polynomials with high degree that are nonzero almost everywhere. „ Using functions defined in pieces, we can fix these two. „ Start: An order-1 B-Spline has blending functions that are always either 1 or 0. When a function is 1, all the rest are zero. „ So an order-1 B-spline is just a sequence of points. „ Any number of control points may be used. „ Now we make higher-order B-splines using a repeated-lirping procedure. „ But this time, we can use any number of control points. CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 7 (c) SE/FIT/HUT 2002 37 B-Splines: The Idea [2/2] „ We form an order-2 B-Spline by lirping between the order-1 blending functions. „ As discussed, we get functions that start at 0, ramp up to 1 and back down, then stay at zero. Each function is 0 most of the time. „ So each blending function is defined in pieces. Each piece is a polynomial of degree 1 (graph is a line). „ So an order-2 B-spline is just the control polygon. „ Again, any number of control points may be used. „ We form an order-3 B-Spline by lirping between the order-2 blending functions. „ Now blending functions are smooth. They start at 0, curve up to 1 then back down. Again, each function is 0 most of the time. „ Again, each blending function is defined in pieces. Each piece is a polynomial of degree 2. „ We continue this repeated-lirping procedure to define B-splines of higher order. „ See the blue book for details and graphs. (c) SE/FIT/HUT 2002 38 Types of B-Splines Approximation Curves Used B-Spline approximations can be classified based on the spacing of the knot vector and the use of weights. 1. Uniform/Periodic B-splines : The spacing is unform and the knots (control points) are equispaced e.g. [0,1,2,3,4,5] These have satisfactory smoothness but lack local control and the starting and ending poits are ill defined as above. 2. Non-periodic: The knots are repeated at the ends m times and the interior is equispaced. e.g. [0 0 0 1 2 3 3 3 ] These can be used to force the control point to start and finish at a control point. 3. Non-uniform B-Splines : The spacing is non- uniform and or repeated knots e.g. [0 1 1 2 4 5 6 6 ] These can be used to obtain local control B-Splines (c) SE/FIT/HUT 2002 39 Ví dụ: Uniform Cubic B-spline on [0,1] „ Four control points are required to define the curve for 0≤t<1 (t is the parameter) „ Not surprising for a cubic curve with 4 degrees of freedom „ The equation looks just like a Bezier curve, but with different basis functions „ Also called blending functions - they describe how to blend the control points to make the curve ( ) ( ) ( ) ( )3332232 1 32 0 3 0 4 6 133316 13646 13316 1 tPtttPttPtttP tBPtP i ii +−++++−+−+−= =∑ = )()( , (c) SE/FIT/HUT 2002 40 Basis Functions on [0,1] 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 t „ Does the curve interpolate its endpoints? „ Does it lie inside its convex hull? B0,4 B1,4 B2,4 B3,4 ( ) ( ) ( ) ( )33 32 2 32 1 1 32 0 6 1 33316 1 3646 1 3316 1 tP tttP ttP tttPtP + −+++ +−+ −+−=)( (c) SE/FIT/HUT 2002 41 Uniform Cubic B-spline on [0,1) „ The blending functions sum to one, and are positive everywhere „ The curve lies inside its convex hull „ The curve does not interpolate its endpoints „ Requires hacks or non-uniform B-splines „ There is also a matrix form for the curve: [ ]                 − − −− = 10001 1333 4063 1331 6 1 2 3 3210 t t t PPPPtP )( (c) SE/FIT/HUT 2002 42 Uniform - B-spline „ Ni,k(u) đa thức B-Spline cơ bản „ Với n+ 1 sô điểm kiểm soát „ Pi điểm kiểm soát thứ i „ k bậc của đường cong 1<k<n+2 „ Ui vector nút của đường cong U=[U1,U2...Un+k+1] i n i ki PuNuP ∑ = = 0 , ).()( )( )( )()()()( 1, 21 1 1,1 1 1 , uNUU uUuN UU UuuN ki kii i ki kii ki ki − −++ + −− −+ −+ − −+− −=   ∈= + others0 ],[1 )( 11, ii i uuu uN CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 8 (c) SE/FIT/HUT 2002 43 Using Uniform B-splines „ At any point t along a piecewise uniform cubic B-spline, there are four non-zero blending functions „ Each of these blending functions is a translation of B0,4 „ Consider the interval 0≤t<1 „ We pick up the 4th section of B0,4 „ We pick up the 3rd section of B1,4 „ We pick up the 2nd section of B2,4 „ We pick up the 1st section of B3,4 (c) SE/FIT/HUT 2002 44 Uniform Cubic B-spline Blending Functions 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 -3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 t B0,4 B1,4 B2,4 B3,4 B4,4 B5,4 B6,4 (c) SE/FIT/HUT 2002 45 Computing the Curve 0 0.05 0.1 0.15 0.2 0.25 -3 -2 .7 -2 .3 -2 -1 .6 -1 .3 -0 .9 -0 .6 -0 .2 0. 1 0. 5 0. 8 1. 2 1. 5 1. 9 2. 2 2. 6 2. 9 3. 3 3. 6 4 4. 3 4. 7 t ( ) ( )∑ = = n k kk tBPtX 0 4, P0B0,4 P1B1,4 P2B2,4 P3B3,4 P4B4,4 P5B5,4 P6B6,4 The curve can’t start until there are 4 basis functions active (c) SE/FIT/HUT 2002 46 (c) SE/FIT/HUT 2002 47 Đặc điểm „ B-spline không đi qua hai điểm đầu và cuối trừ khi hàm hợp được dùng là tuyến tính. „ B-spline có thể được tạo qua hai điểm đầu, cuối và tiếp xúc với vector đầu và cuối của đa giác kiểm soát. Bằng cách thêm vào các nút tại vị trí của các nút cuối của vector tuy nhiên các giá trị giống nhau không nhiều hơn bậc của đường cong. „ Tính chất bao lồi của đa giác kiểm soát và tính chất chuẩn được thoa mãn. „ Số lượng các nút, bậc của đường cong và số điểm điều khiển luôn có các quan hệ ràng buộc: „ 0 ≤ u ≤ n - k + 2 1(u)N n 0i ki, =∑ = (c) SE/FIT/HUT 2002 48 ( )   ≤≤= + otherwise 0 1 1 1, kk k ttt tB B-Spline Blending Functions „ The recurrence relation starts with the 1st order B-splines, just boxes, and builds up successively higher orders „ This algorithm is the Cox - de Boor algorithm ( ) ( ) ( )tB tt tt tB tt tttB dk kdk dk dk kdk k dk 1,1 1 1, 1 , −+ ++ + − −+     − − +    − −= CNTT-DHBK Hanoi hunglt@it-hut.edu.vn 9 (c) SE/FIT/HUT 2002 49 Bk,1 B 0,1 0 0.2 0.4 0.6 0.8 1 1.2 -3 -2 .8 -2 .6 -2 .4 -2 .2 -2 -1 .8 -1 .6 -1 .4 -1 .2 -1 -0 .8 -0 .6 -0 .4 -0 .2 0 0. 2 0. 4 0. 6 0. 8 1 t B 0, 1( t) B 2,1 0 0.2 0.4 0.6 0.8 1 1.2 -3 -2 . 8 -2 . 6 -2 . 4 -2 . 2 -2 -1 . 8 -1 . 6 -1 . 4 -1 . 2 -1 -0 . 8 -0 . 6 -0 . 4 -0 . 2 0 0.2 0.4 0.6 0.8 1 t B 2, 1( t) B 3,1 0 0.2 0.4 0.6 0.8 1 1.2 -3 -2 .8 -2 .6 -2 .4 -2 .2 - 2 -1 .8 -1 .6 -1 .4 -1 .2 - 1 -0 .8 -0 .6 -0 .4 -0 .2 0 0.2 0.4 0.6 0.8 1 t B 3, 1( t) B 1,1 0 0.2 0.4 0.6 0.8 1 1.2 -3 -2. 8 -2. 6 -2. 4 -2. 2 -2 -1. 8 -1. 6 -1. 4 -1. 2 -1 -0. 8 -0. 6 -0. 4 -0. 2 0 0.2 0.4 0.6 0.8 1 t B 1, 1( t) (c) SE/FIT/HUT 2002 50 Bk,2 B 0,2 0 0.2 0.4 0.6 0.8 1 1.2 -3 -2 .8 -2 .6 -2 .4 -2 .2 -2 -1 .8 -1 .6 -1 .4 -1 .2 -1 -0 .8 -0 .6 -0 .4 -0 .2 0 0. 2 0. 4 0. 6 0. 8 1 t B 0, 2( t) B 1,2 0 0.2 0.4 0.6 0.8 1
Tài liệu liên quan