1 / 27

COM335

TOPIC 5. DRAWING CURVES. COM335. Two types of curve :. Regular curves. Which have a simple equation. For example the circle x 2 + y 2 = r 2 The equation is used, usually in parametric form to draw the curve. General curves.

Download Presentation

COM335

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TOPIC 5 DRAWING CURVES COM335

  2. Two types of curve : Regular curves Which have a simple equation. For example the circle x2 + y2 = r2 The equation is used, usually in parametric form to draw the curve. General curves Either have no equation which describes their properties or their equation if known is too complex to use in practice. For example the shape of a car body, a ships hull, the profile of a leaf. COM335

  3. COM335

  4. All curves will be drawn as line segments between nodes Generally speaking we wish to minimise the number of nodes we store - particularly for general curves COM335

  5. Regular curves COM335

  6. Y 0 1 2 3 4 5 6 7 8 9 10 X

  7. Parametric form of the equation

  8. (XF,YF) t = 1 (X,Y) t = 0.3 t = 0 (XS,YS) b = (XF – XS) a = XS c = YS d = (YF – YS) X = XS + t*(XF – XS) Y = YS + t*(YF – YS) COM335

  9. (x,y)  x = Rcos() y = Rsin() Parametric form of the equation for a circle COM335

  10. (-Y,X) (Y,X) (X,Y) (-X,Y) (X,-Y) (-X,-Y) (Y,-X) (-Y,-X) Exploiting symmetry in the circle

  11. Regular curves you might draw 2D the ellipse Method 1 : use the parametric equation of the ellipse : x = a cos() & y = bsin() Method 2 : Draw a circle of radius 1and then do a 2D scaling transform by ‘a’ in the x direction and by ‘b’ in the y direction 3D the helix Use the parametric equation of the helix : x = Rcos() & y = Rsin() z = C  COM335

  12. General curves COM335

  13. Parametric cubic equations

  14. P1 P2 P0 P3 Figure 4.4 The Bezier Curve

  15. = t At 0 = + + + x a a . 0 a . 0 a . 0 0 0 1 2 3 - ( x x ) dx = + + = 1 0 a 2 . a . 0 3 . a . 0 1 2 3 1 dt 3 = t 1 At = + + + x a a . 1 a . 1 a . 1 1 0 1 2 3 - dx ( x x ) = + + = 3 2 a 2 . a . 1 3 . a . 1 1 2 3 1 dt 3 Applying the boundary conditions for ‘x’ equation

  16. Drawing a Bezier curve segment in MATLAB function Bezierdemo(N) %To demonstrate drawing a simple Bezier curve %N is the 4x2 control node array %Draw the control nodes and convex hull plot(N(:,1),N(:,2),'-o') axis([0,10,0,10]); hold on %calculate the Bezier curve positions at 10 points k = 0; xx = zeros(1,11); yy = zeros(1,11); for t = 0:0.1:1 k = k+1; xx(k) = ((1-t)^3)*N(1,1) +3*t*((1-t)^2)*N(2,1)+3*(t^2)*(1-t)*N(3,1)+(t^3)*N(4,1); yy(k) = ((1-t)^3)*N(1,2) +3*t*((1-t)^2)*N(2,2)+3*(t^2)*(1-t)*N(3,2)+(t^3)*N(4,2); end %Use interpolation to get a smooth curve xxi = [N(1,1):0.01:N(4,1)]; yyi = interp1(xx,yy,xxi,'spline'); plot(xxi,yyi,'Color','red', 'LineWidth',2) COM366

  17. Entering the data and drawing the result >> N = [1 2; 2 5;6 8;8 3] N = 1 2 2 5 6 8 8 3 >> Bezierdemo(N) COM366

  18. P2 P1 P6 P3 P3 P0 P4 P5 Figure 4.6 : P2, P3 & P4 are co-linear to achieve continuity Joining Bezier Curves

  19. Ni+1 Ni Si+1 Si Ni-1 Figure 4.7 : Spline Segments

  20. Natural Spline End Conditions

  21. Method Notes Nearest Selects the nearest node point. Results in a set discontinuous segments Linear Draws a straight line between each pair of nodes. Results in abrupt gradient changes at the nodes. Spline Natural cubic spline interpolation. The ‘free end’ end condition is used as a default. In fact interp1 with a spline method calls a more basic ‘spline’ function in which you can define any of the three end conditions. Pchip, cubic A cubic Hermite polynomial function. You will find this referred to in the graphics literature but the mathematics is beyond this course. V5cubic Not much use now but is the cubic interpolation scheme used in MATLAB 5 Interpolation methods for the MATLAB interp1 function COM366

  22. function Interptest %To test the errors of various interpolation methods %The test curve is a sine curve between 0 and 180 degrees x = [0:pi/6:pi]; y = sin(x); subplot(2,1,1); plot(x,y,'ro') axis([0 pi -0.05 1.1]) hold on %Now interpolate with various methods %Alternatives to try : % 'nearest' % 'linear' % 'spline' % 'cubic' xi = [0:pi/60:pi]; yi = interp1(x,y,xi,'spline'); subplot(2,1,1);plot(xi,yi) hold off %Now calculate the true values and display errors yt = sin(xi); error = yt - yi; subplot(3,1,3); plot(xi,error) %To see the errors clearly change the y range as follows % nearest -0.5 0.5 % linear -0.05 0.05 % 'cubic' -0.02 0.02 % 'spline' -0.002 0.002 axis([0 pi -0.002 0.002]) COM335

  23. Errors with linear interpolation COM366

  24. Errors with cubic interpolation COM335

  25. Errors with spline interpolation COM335

  26. COM335

More Related