You are on page 1of 13

1

MATHEMATICAL MODELING OF SYNTHETIC CURVES IN MATLAB


Prepared by
Akshat Agha 2009A4PS380G

Prepared for
D.M. Kulkarni

In partial fulfillment of requirements of the course

BITS C331
Computer Oriented Project

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE PILANI- K.K. BIRLA GOA CAMPUS
November, 2012

ACKNOWLEDGEMENT
The report is written under the supervision Associate Professor Dr. D.M. Kulkarni, who has given valuable inputs and suggestions. I also like to thank Harshit Pathak, Poorwa Shekhar, Suraj R. Pawar, Krati Agarwal and Aditya Ramani who have worked on the same project. Akshat Agha 2009A4PS380G

ABSTRACT
The project is concerned with mathematical modeling of geometric curves using MATLAB. Two categories of curves are modeled. Analytic curves, which are conic sections, which were covered, are as follows: 1. 2. 3. 4. 5. Line Parabola Hyperbola Ellipse Circle

Synthetic curves, which include the category of splines, which were covered are as follows: 1. Hermite Cubic Spline 2. Bezier Curves Each part of the report provides an introduction to the curve and its parametric form. The code for the implementation of the curve on MATLAB is also included.

INDEX
S.No 1. 2. Contents Introduction Geometric Modeling using MATLAB 2.1 Line 2.2 Circle 2.3 Parabola 2.4 Ellipse 2.5 Hyperbola 2.6 Synthetic Curves 2.6.1 Hermite Cubic Spline 2.6.2 Bezier Curve References Page No. 5 6 6 6 7 8 9 10 10 11 13

3.

INTRODUCTION
CAD (Computer Aided Design) is used all over the world by many different types of engineering manufacturers. In industry, CAD refers to any computer software that is used to produce high quality drawings and models which meet exact specifications. CAD software is often then linked to machinery to perform a task to manufacture part of or a whole product; this is known as CAM (Computer Aided Manufacture). Computer aided Design is a sub-process of Design process.

Computer Graphics

CAD

Design Engineering

Geometric Modeling

Network

CAM
Manufacturing
CAD

GEOMETRIC MODELING USING MATLAB


Geometric or surface modeling traditionally identifies a body of techniques that can model certain classes of piecewise parametric surfaces, subject to particular conditions of shape and smoothness. It developed as a separate field in several industries, including automobile, aerospace, and ship building, and has some of its intellectual roots in approximation theory. All CAD/CAM systems provide users with curve entities. Curve entities are divided into two categories: Analytic Points, lines, arcs, fillets, chamfers, and conics (ellipses, parabolas, and hyperbolas) Synthetic Includes various types of spline; Cubic spline, B-spline and Bezier curve

1. Line
A line connecting two end points P1 and P2 has a parametric equation: P = P1 + u(P2 P1), where 0u1
global p1 p2 p3 num u y x l p q p=[] q=[] num=inputdlg('Enter first point [x1 y1]') p1=str2num(num{1}) num = inputdlg('Enter second point [x2 y2]') p2=str2num(num{1}) u=0:0.1:1 y=p1(2) + u*(p2(2)-p1(2)) q=[q;y] x=p1(1)+u*(p2(1)-p1(1)) p=[p;x] plot(x,y) %p3=p1 + u*(p2-p1) %plot(u,p3) axis equal

4 3.5 3 2.5 2 1.5 1 0.5 0 -1

-0.5

0.5

1.5

2.5

3.5

2. Circle
The basic parametric equation of a circle of radius r and center (xc,yc) is: X = xc + r cos(u) Y = yc + r sin(u), where 0u2

7
global x y theta temp1 temp2 r u temp1=inputdlg('Enter radius') r=str2num(temp1{1}) temp2=inputdlg('Enter step value') %'CIRCLE',1,'0.1', options) u=str2num(temp2{1}) theta=-pi:u:pi x=r*cos(theta) y=r*sin(theta) plot(x,y) axis equal

3 2 1 0 -1 -2 -3

-5

-4

-3

-2

-1

3. Parabola
A parabola is the curve created when a plane intersects a right circular cone parallel to the side (elements) of the cone. The parametric equation in 2-D for a parabola is: X = xv + Au2 Y = yv + 2Au, where 0u
global c a v global x y ym u p q x = [] y = [] prompt={'Vertex','Focal Length','Increment Value'}; name='Parabola'; numlines=1; defaultanswer={'0 0','1','0.1'}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer=inputdlg(prompt,name,numlines,defaultanswer,options); c=str2num(answer{1}); a=str2num(answer{2}); v=str2num(answer{3}); 150 u=0:v:10 100 p = u.*u q = u.*a 50 x = c(1) + (a.*p) y = c(2) + (2.*q) 0 ym=-y -50 hold on plot(x,y) -100 plot(x,ym) -150 axis equal
0 50 100 150 200 250 300 350 400 450 500

8 4. Ellipse
An ellipse is the curve created when a plane cuts all the elements (sides) of the cone but its not perpendicular to the axis. The basic equation of an ellipse with center (xc,yc) and radii a,b is: X = xc + a cos(u) Y = yc + b sin(u), where 0u2
%[output] = tablerot(v0,th0,mu,omg) %DIALOGUE BOX GENERATION prompt={'CENTER OF ELLIPSE X','CENTER OF ELLIPSE Y','MAJOR AXIS','MINOR AXIS'}; name='Simulation ELLIPSE'; %SETTING THE DEFAULT VALUES numlines=1;defaultanswer={'0','0','1','1'}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; %INPUTTING THE VALUES answer=inputdlg(prompt,name,numlines,defaultanswer,options); %CHANGING THE INPUTTED STRING INTO NUMERICAL VALUES cx=str2num(answer{1}); cy=str2num(answer{2}); a=str2num(answer{3}); 6 b=str2num(answer{4}); N=1000; 4 TH=0.36; for i=1:N 2 p(i)=cx+a/2*cos(i*TH); 0 q(i)=cx+b/2*sin(i*TH); end -2 plot(p,q) lm = max([max(abs(p)) max(abs(q))]); -4 lm = lm+2; axis([-lm lm -lm lm]); -6 axis square -6 hold off

-4

-2

9 5. Hyperbola
A hyperbola is the curve created when a plane parallel to the axis and perpendicular to the base intersects a right circular cone. The parametric equation in 2-D is: X = xv + Acoshu Y = yv + Bsinhu

prompt={'ABSICCA OF CENTER','ORDINATE OF CENTER','MAJOR AXIS','MINOR AXIS'}; name='Simulation HYPERBOLA'; numlines=1;defaultanswer={'0','0','1','1'}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer=inputdlg(prompt,name,numlines,defaultanswer,options); cx=str2num(answer{1}); cy=str2num(answer{2}); a=str2num(answer{3}); b=str2num(answer{4}); 30 TH=0.1; for i=-20:20 20 p(i+21)=cx+a*cosh(i*TH); q(i+21)=cy+b*sinh(i*TH); 10 r(i+21)=cx-a*cosh(i*TH); 0 s(i+21)=cy-b*sinh(i*TH); end -10 plot(p,q,r,s) lm = max([max(abs(p)) max(abs(q))]); -20 lm = lm+2; axis([-lm lm -lm lm]); -30 axis square
-30 -20 -10 0 10 20 30

10 6. Synthetic Curves 1. Hermite Cubic Spline


On the unit interval , given a starting point p0 at and an ending point p1 at with starting tangent m0 at and ending tangent m1 at , the polynomial can be defined by :

where t [0, 1].


%Taking all relevant inputs from user prompt={'First Point','Second Point','First Tangent','Second Tangent','Increment Value'}; name='Hermite Curve'; numlines=1; defaultanswer={'3 2','11 5','5 0','5 0','0.1'}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; answer=inputdlg(prompt,name,numlines,defaultanswer,options); p1=str2num(answer{1}); 5 p2=str2num(answer{2}); 4.5 t1=str2num(answer{3}); t2=str2num(answer{4}); 4 inc=str2num(answer{5}); global h 3.5 %Defining Hermite matrix 3 h=[2 -2 1 1; -3 3 -2 -1; 0 0 1 0; 1 0 0 0] global t p1 num p2 t1 t2 c inc 2.5 %Defining the working matrix of points and tangents c=[p1;p2;t1;t2] 2 3 4 5 6 7 8 global x y s j temp1 m1 temp2 temp3 %Defining x and y as matrices of undefined size x=[] y=[] %For loop for calculating values of x and y by incrementing s as per user input for s =0: inc :1 t=[s^3 s^2 s 1] temp1 = c(1:4,1:1) m1 = t*h temp3 = m1*temp1 x=[x;temp3] temp2 = c(1:4,2:2) temp3=m1*temp2 y=[y;temp3] j=j+1 end %Plotting all results to obtain final Hermite curve plot(x,y); axis square

10

11 2. Bezier Curve
Four points P0, P1, P2 and P3 in the plane or in higher-dimensional space define a cubic Bzier curve. The curve starts at P0 going toward P1 and arrives at P3 coming from the direction of P2. Usually, it will not pass through P1 or P2; these points are only there to provide directional information. The distance between P0 and P1 determines "how long" the curve moves into direction P2before turning towards P3. The parametric form of the curve is given as:

%DIALOGUE BOX GENERATION prompt={'Number of points'}; name='Bezier curve'; %SETTING THE DEFAULT VALUES numlines=1;defaultanswer={'4'}; options.Resize='on'; options.WindowStyle='normal'; options.Interpreter='tex'; %INPUTTING THE VALUES answer=inputdlg(prompt,name,numlines,defaultanswer,options); %CHANGING THE INPUTTED STRING INTO NUMERICAL VALUES n=str2num(answer{1}); 5 count = 1; px = []; 4.5 py = []; for k=1:n 4 prompt={'x coordinate','y coordinate'}; 3.5 name='Enter points'; %SETTING THE DEFAULT VALUES 3 numlines=1;defaultanswer={'1','1'}; options.Resize='on'; 2.5 options.WindowStyle='normal'; options.Interpreter='tex'; 2
1.5 1

1.5

2.5

%INPUTTING THE VALUES answer=inputdlg(prompt,name,numlines,defaultanswer,options); %CHANGING THE INPUTTED STRING INTO NUMERICAL VALUES px(count)= str2num(answer{1}); py(count)= str2num(answer{2}); count=count+1; end

12
ax=0; ay=0; count=1; n=n-1; for u=0:0.01:1 for i=0:n b=(factorial(n)/factorial(n-i)/factorial(i))*(u^i)*(1-u)^(n-i); ax=ax+px(i+1)*b; ay=ay+py(i+1)*b; end qx(count)=ax; qy(count)=ay; ax=0; ay=0; count=count+1; end plot(qx,qy);

13

References
1. www.mathworks.in 2. www.math.utah.edu

You might also like