Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 COM335 TOPIC 5 DRAWING CURVES

2 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 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.

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

5 COM335 Regular curves

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

7 Parametric form of the equation

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

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

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

11 COM335 Regular curves you might draw 2D the ellipse 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 Method 1 : use the parametric equation of the ellipse : x = a cos(  ) & y = bsin(  ) 3D the helix Use the parametric equation of the helix : x = Rcos(  ) & y = Rsin(  ) z = C 

12 COM335 General curves

13 Parametric cubic equations

14 P0P0 P1P1 P2P2 P3P3 Figure 4.4 The Bezier Curve

15 Applying the boundary conditions for ‘x’ equation

16

17 COM366 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)

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

19 P0P0 P1P1 P2P2 P3P3 Figure 4.6 : P 2, P 3 & P 4 are co-linear to achieve continuity P3P3 P4P4 P5P5 P6P6 Joining Bezier Curves

20 N i-1 NiNi N i+1 SiSi S i+1 Figure 4.7 : Spline Segments

21 Natural Spline End Conditions

22 COM366 MethodNotes NearestSelects the nearest node point. Results in a set discontinuous segments LinearDraws a straight line between each pair of nodes. Results in abrupt gradient changes at the nodes. SplineNatural 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, cubicA cubic Hermite polynomial function. You will find this referred to in the graphics literature but the mathematics is beyond this course. V5cubicNot much use now but is the cubic interpolation scheme used in MATLAB 5 Interpolation methods for the MATLAB interp1 function

23 COM335 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])

24 COM366 Errors with linear interpolation

25 COM335 Errors with cubic interpolation

26 COM335 Errors with spline interpolation

27 COM335


Download ppt "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."

Similar presentations


Ads by Google