Mathematical Modeling of Synthetic Curves

Embed Size (px)

Citation preview

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    1/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

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    2/13

    2

    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

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    3/13

    3

    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. Line2. Parabola3. Hyperbola4. Ellipse5. Circle

    Synthetic curves, which include the category of splines, which were covered are as

    follows:

    1. Hermite Cubic Spline2. 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.

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    4/13

    4

    INDEX

    S.No Contents Page No.

    1. Introduction 5

    2. Geometric Modeling using MATLAB 6

    2.1 Line 6

    2.2 Circle 6

    2.3 Parabola 7

    2.4 Ellipse 82.5 Hyperbola 9

    2.6 Synthetic Curves 10

    2.6.1 Hermite Cubic Spline 10

    2.6.2 Bezier Curve 11

    3. References 13

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    5/13

    5

    Network

    CADManufacturing

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

    ComputerGraphics

    GeometricModeling

    DesignEngineering

    CAD

    CAM

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    6/13

    6

    -1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 40

    0.5

    1

    1.5

    2

    2.5

    3

    3.5

    4

    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 shapeand 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:

    AnalyticPoints, lines, arcs, fillets, chamfers, and conics (ellipses, parabolas, and hyperbolas)

    SyntheticIncludes 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

    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/29/2019 Mathematical Modeling of Synthetic Curves

    7/13

    7

    -5 -4 -3 -2 -1 0 1 2 3 4 5

    -3

    -2

    -1

    0

    1

    2

    3

    0 50 100 150 200 250 300 350 400 450 500

    -150

    -100

    -50

    0

    50

    100

    150

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

    Aparabola 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});

    u=0:v:10

    p = u.*u

    q = u.*a

    x = c(1) + (a.*p)

    y = c(2) + (2.*q)

    ym=-y

    hold on

    plot(x,y)

    plot(x,ym)axis equal

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    8/13

    8

    -6 -4 -2 0 2 4 6

    -6

    -4

    -2

    0

    2

    4

    6

    4. EllipseAn 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});

    b=str2num(answer{4});N=1000;

    TH=0.36;

    for i=1:N

    p(i)=cx+a/2*cos(i*TH);

    q(i)=cx+b/2*sin(i*TH);

    end

    plot(p,q)

    lm = max([max(abs(p)) max(abs(q))]);

    lm = lm+2;

    axis([-lm lm -lm lm]);

    axis squarehold off

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    9/13

    9

    -30 -20 -10 0 10 20 30

    -30

    -20

    -10

    0

    10

    20

    30

    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});

    TH=0.1;

    for i=-20:20

    p(i+21)=cx+a*cosh(i*TH);

    q(i+21)=cy+b*sinh(i*TH);

    r(i+21)=cx-a*cosh(i*TH);

    s(i+21)=cy-b*sinh(i*TH);

    end

    plot(p,q,r,s)

    lm = max([max(abs(p)) max(abs(q))]);

    lm = lm+2;

    axis([-lm lm -lm lm]);

    axis square

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    10/13

    10

    3 4 5 6 7 8 9 102

    2.5

    3

    3.5

    4

    4.5

    5

    6. Synthetic Curves

    1. Hermite Cubic Spline

    On the unit interval , given a starting pointp0 at and an ending point p1 atwith 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});

    p2=str2num(answer{2});

    t1=str2num(answer{3});

    t2=str2num(answer{4});

    inc=str2num(answer{5});

    global h

    %Defining Hermite matrix

    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

    %Defining the working matrix of points and tangents

    c=[p1;p2;t1;t2]

    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

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    11/13

    11

    1 1.5 2 2.51

    1.5

    2

    2.5

    3

    3.5

    4

    4.5

    5

    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 ofP2. 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});

    count = 1;

    px = [];

    py = [];

    for k=1:n

    prompt={'x coordinate','y coordinate'};

    name='Enter points';

    %SETTING THE DEFAULT VALUES

    numlines=1;defaultanswer={'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

    px(count)= str2num(answer{1});

    py(count)= str2num(answer{2});

    count=count+1;

    end

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    12/13

    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);

  • 7/29/2019 Mathematical Modeling of Synthetic Curves

    13/13

    13

    References

    1. www.mathworks.in2. www.math.utah.edu