m 2009 Ceit 09 Uwamahoro Marie Claire Gs20050714

download m 2009 Ceit 09 Uwamahoro Marie Claire Gs20050714

of 50

Transcript of m 2009 Ceit 09 Uwamahoro Marie Claire Gs20050714

  • i

    DECLARATION

    We confirm that the work entitled 3D SOLID GRAPHICS USING BEZIER

    CURVE AND THEIR APPLICATIONS submitted to Kigali institute of Science and

    Technology, KIST in partial fulfillment of the requirements for the award of the

    degree in Bachelor of Science in Computer Engineering and Information

    Technology, BSCEIT is our own and the appropriate credit has been given where

    reference has been made to the work of others.

    We further declare that the work reported in this project has not and will not be for

    the award of any submitted, for the award of any other degree or diploma in this

    Institute or any other institute or university in Rwanda.

    Signed by UWABYAYE Clmentine UWAMAHORO Marie Claire Reg NoGS20050713 Reg NoGS20050714 . ..

  • ii

    KIGALI INSTITUTE OF SCIENCE AND TECHNOLOGY

    INSTITUT DES SCIENCES ET DE TECHNOLOGIE DE KIGALI

    Avenue de l'Arme, B.P. 3900 Kigali, Rwanda

    FACULTY OF ENGENEERING

    DEPARTMENT OF COMPUTER ENGINEERING AND INFORMATION

    TECHNOLOGY

    C E R T I F I C A T E

    This is to certify that the Project Work entitled 3D SOLID GRAPHICS USING

    BEZIER CURVE AND THEIR APPLICATIONS is a record of the original work

    done by UWABYAYE Clementine (REG.NO:GS20050713)and UWAMAHORO

    Marie Claire(REG.No: GS20050714) in partial fulfillment of the requirement for the

    award of Bachelor of Science Degree in information Technology of Kigali Institute

    of Science and Technology (KIST) during the Academic Year 2009.

    ..

    (Dr. GAURAV Bajpai) MWAKIJELE Jonathan

    Supervisor HEAD, Dept. of CEIT

    Submitted for the Project Examination held at KIST on May 2009

  • iii

    DEDICATION To the Almighty God our Guide To my beloved mother MUKESHIMANA Spciose To all members of my family. To my beloved daughter IHORERE Lina Tania. UWABYAYE Clmentine To the Almighty God our Guide To my beloved husband BISANGWA Modeste To my beloved first born CYUZUZO Lisa Chanelle To my beloved mother MukaBucyana Asterie To my beloved Sisters To my family and family- in-law UWAMAHORO Marie Claire

  • iv

    ACKNOWLEDGEMENTS

    We acknowledge that what we have achieved was through the help of almighty God

    Who gave us the strength, courage and determination to carry out our responsibilities.

    We also thank our supervisor Dr.GAURAV Bajpai for all his help, feedback, time,

    patience and assistance in this project.

    We would like to thank our parents for giving us a birth, for their education, help, and

    assistance since our infancy.

    We would like to thank the following families for their help during this project.

    Family of MURENGERANTWALI Mathias, family of MUDAHERANWA Norbert

    and Family of Ntirushwa J.Baptiste.

    Thanks to all student of IT for their advices about how to tackle the project and

    warnings of some of the pitfalls to avoid. Thanks to those who gave up their time to

    be a part of the project; It was truly appreciated.

    Finally yet important, we greatly appreciate our friends, neighbors and colleagues for

    their moral and material support that highly contributed to our success.

    May God bless you All.

  • v

    ABSTRACT

    3D solid graphics using Bezier curve is a project which covers a range of techniques.

    The literature contains works of how Bezier curve are used in creating 3D solid and

    providing its smoothness. Three dimensional solid graphics are widely used in

    various applications.

    The project contains full explanation of Bezier curve as the main element of the

    project; including algorithm used to draw this curve.

    Java netbeans IDE and JDK 6U12 will be introduced to draw different position, of

    Bezier curve. The reason of choosing java programming language as a favored

    language will be also included in this project

    Finally, different applications of created 3D solid in different areas will be discussed.

  • vi

    TABLE OF CONTENTS

    DECLARATION .................................................................................................................................. i C E R T I F I C A T E ......................................................................................................................... ii ACKNOWLEDGEMENTS ............................................................................................................... iv ABSTRACT ........................................................................................................................................ v TABLE OF CONTENTS ................................................................................................................... vi LIST OF ABBREVIATION ............................................................................................................ viii CHAPTER 1: BACKGROUND ......................................................................................................... 1

    1.1 Overview of the project ............................................................................................................. 1 1.2 Introduction ............................................................................................................................... 1

    1.2.1 History of Bezier curve ...................................................................................................... 2 1.2.2 Properties of Bezier curve .................................................................................................. 3 1.2.3. Java .................................................................................................................................... 4 1.2.4 Problem statement .............................................................................................................. 8 1.2.5 Aims of the project ............................................................................................................. 8 1.2.6 Objectives of the project ..................................................................................................... 8 1.2.7 Project scope ....................................................................................................................... 9

    1.3 Methodology ............................................................................................................................. 9 CHAPTER 2: LITERATURE REVIEW .......................................................................................... 10

    2.1 Introduction ............................................................................................................................. 10 2.1.1 A solid .............................................................................................................................. 10 2.1.2 Bezier curve ...................................................................................................................... 10 2.1.3 Java 3D ............................................................................................................................. 10 2.1.4 3D graphics ....................................................................................................................... 11

    CHAPTER 3: ANALYSIS AND IMPLEMENTATION ................................................................. 12 3.1 Overview ................................................................................................................................. 12 3.2 Analysis ................................................................................................................................... 12

    3.2.1 Constructive Bezier Curve Algorithm .............................................................................. 13 3.2.2 Basic Algorithm ............................................................................................................... 13 3.2.3 Special & General Cases .................................................................................................. 14 3.2.4 Parametric equation of degree n ....................................................................................... 16 3.2.4 Analyzing the Bezier curve By Fourier series .................................................................. 17

    3.3 Implementation ........................................................................................................................ 21 3.3.1 Drawing a Bezier curve .................................................................................................... 22 3.3.2 Bezier curve transformation ............................................................................................. 24

    CHAPTER 4 APPLICATION OF 3D SOLID GRAPHICS ............................................................. 26 4.1.1 Three-Dimensional graphics in Radiotherapy .................................................................. 26 4.1.2 Three-dimensional solid graphics in Biomechanics ......................................................... 27

    4.2 Three-dimensional solid graphics in multimedia .................................................................... 28 4.3 Three dimensional solid graphics in Graphical User Interface (GUI) .................................... 29 4.5 Three-dimensional solid graphics in Business graphics and presentation .............................. 29 4.6 Three-dimensional solid graphics in Computer Aided design (CAD) .................................... 30

    CHAPTER 5 CONCLUSION AND FUTURE WORK .................................................................... 31 5.1 Conclusion ............................................................................................................................... 31 5.2 extension and future work ....................................................................................................... 31

    5.2.1 Improvements ................................................................................................................... 31 5.2.2 Extensions ........................................................................................................................ 31

    REFERENCES AND BIBLIOGRAPHY ......................................................................................... 32

  • vii

    LIST OF FIGURES Figure1: Steps for creating and running a java program5

    Figure2: Bytecode6

    Figure3 : Java running environment22

    Figure4: Linear Bezier curve23

    Figure5: Quadratic Bezier curve23

    Figure6: Cubic Bezier curve..24

    Figure7: Closed Bezier curve.24

  • viii

    LIST OF ABBREVIATION

    API Application Programmers Interface AWT Abstract Window Toolkit. CAD Computer Aided Design. CD Compact Disk. CE&IT Computer Engineering and Information Technology. CT Computed Tomography. Dr Doctor. DVD Digital Video Disk. GUI Graphical User Interface. HOD Head of department. IDE Integrated Development Environment. IT Information Technology. JDK-6u12 Java Development tool Kit module six update to12 in Windows Platform. JVM Java Virtual Machine. MR Magnetic Resonance. PDA Personal Data Assistants ROM Read Only Memory. TV Television. VCR Videocassette Recorder. WYSIWYG What You See, Is What You Get. ZUI zooming user Interface. 3D Three Dimension.

  • 1

    CHAPTER 1: BACKGROUND

    This chapter begins with an overview of the project followed by a brief introduction to

    the topic, including the history of Bezier curve. The selected task which were to be

    completed are briefly explained.

    1.1 Overview of the project

    The project was designed to generate 3D solid graphics with the help of Bezier curve

    using java programming language. An analysis of different method which could be

    employed to produce the final shape within the time frame was undertaken.

    1.2 Introduction

    Three dimensional graphics is a part of computer graphics concerned with generating and

    displaying three-dimensional objects in a two-dimensional space. Computer graphics is

    one of attractive and rapidly developing fields of information technology. Its popularity is

    closely connected to the development of computers and their availability to the wider

    public. The basis of today's communication of computer users is interaction based on the

    idea What You See, Is What You Get? (WYSIWYG). Such communication contributes

    to advancing the relationship of a software product or application with its user.

    3D graphics allow object (solid) to be created on a X-Y-Z scale (width, height, depth ).

    As 3D entities ,they can be rotated& viewed from all angles as well as be scaled larger or

    smaller, moved from one position to another position parallel and sheared. This means

    that a solid will be created, displayed and manipulated in the computer in three

    dimensions from 2D Bezier curve.

    This language will not only allow us to create 3D solid graphics but also to edit the

    created graphics.

  • 2

    We will first make a java code to draw the basic element of computer graphics called

    Bezier curve which provide the smoothness of the body, after creating it we shall use

    other codes to move it from position 1 to position 2 . there we will be having a 3D solid

    graphic and try to look out of the reason of creating this shape, why is it needed, in brief

    what is their applications?

    1.2.1 History of Bezier curve Bezier curve was developed by the French mathematician and Engineer Pierre Bezier in

    the late 1960s while working for the car manufacturer Renault for use in the design of

    Renault automobile bodies. Pierre Bezier was looking for a way to describe a curve with

    mathematical precision that would enable it to be scaled and copied without loss of

    accuracy. Although he used a 3D form of the curve to

    Specify a solid car body model; its the 2D version that has become the mainstay of

    Computer graphics applications.

    Bezier curves have a number of properties that make them highly useful and convenient

    for curve and surface design. They are also easy to implement. For these reasons, Bezier

    curve are widely available in various CAD (Computer Aided design) software, in general

    graphics packages (such as GL on Silicon Graphics systems), and in assorted drawing

    and painting packages(such as Aldus Superpaint and Cricket Draw).[1]

    The method by which Bezier developed these curves is relatively simple. He began by

    defining a curve contained within a cube. This curve was given by a parametric equation

    equal to y=x2 And then by transforming the cube into any kind of parallelepiped,

    naturally the curve changes shape. In other words the shape of the resulting

    parallelepiped determines the shape of the parametric curve. The four control points are

    the vertices of an imaginary parallelepiped. Bezier used the four vertices to describe the

    shift of the parallelepiped and therefore the shape of the resulting curve. Because the

  • 3

    curve is always within this imaginary parallelepiped, it can be said that the curve is

    contained completely within the convex hull of its control points. (The control points

    are the vertices that define the parallelepiped.)[1]

    1.2.2 Properties of Bezier curve

    1.2.2.1 A very useful property of a Bezier curve is that it always passes through the first

    and last control points. In general it will not pass through any other control points, but its

    shape mimics that one of the control polygon. Thus, the slope at the beginning of the

    curve is along the line joining the first two control points, and the slope at the end of the

    curve is along the line joining the last two endpoints.

    1.2.2.2 Another important property of any Bezier curve is that it lies within the convex

    hull (convex polygon boundary) of the control points. This follows from the properties of

    Bezier blending functions: They are all positive and their sum is always equal to 1.

    ,0

    ( ) 1n

    i ni

    b t P i=

    = (1 ) 1.2.2.3 Bezier curve have another important property that the tangent to the curve at an

    endpoint is along the line joining that endpoint to the adjacent control point.

    1.2.2.4 Adjusting the position of a control point changes the shape of the curve in a

    predictable manner. This means that the curve follows the control points.

    1.2.2.5 Bezier curve is defined on n+1 points P0,Pn and can be represented as a

    polynomial curve of degree n.

    1.2.2.6 Adding multiple control points at a single position in space will add more weight

  • 4

    to that point pulling the Bezier curve towards it.

    1.2.2.7 Closed curves can be generated by making the last control point the same as the

    first control point. First order continuity can be achieved by ensuring the tangent between the

    first two points and the last two points are the same.

    1.2.2.8 The blending function is always a polynomial one degree less than the number of

    control points. Thus 3 control points results in a parabola, 4 control points a cubic curve etc.

    1.2.3. Java

    The term Java actual refers to more than just a particular language like C or Pascal. Java

    encompasses several parts, including :

    A high level language: the Java language is a high level and offers many unique

    features of its own. [2]

    Java bytecode: a compiler, such as Sun's javac, transforms the Java language source

    code to bytecode that runs in the JVM. [2]

    Java Virtual Machine (JVM): a program, such as Sun's java, that runs on a given

    platform and takes the byte code programs as input and interprets them just as if it were

    a physical processor executing machine code.[2]

    Procedure for running a Java Program

    The essential steps to creating and running Java programs go as follows:

    Create a Java source code file

    Compile the source code

    Run the compiled code in a Java Virtual Machine.

  • 5

    The following figure illustrates these steps:

    Figure 1: Steps for creating and running a Java program.[3]

    Public class test{ Float A,B; Test( ){ A=23; B=19; Float X=A*B;

    Java compiler

    Java virtual machine

  • 6

    Figure2: Java bytecode for the JVM generated in many ways. [4]

    The shaded boxes in the figure2 presents the standard procedure taken with Sun's JDK

    tools javac for compilation of source code to bytecode, and java virtual machine to run

    the programs.

    The unshaded boxes, however, shows many variations from this standard approach by

    using third-party tools. One can find independent sources for Java compilers, JVMs, and

    even compilers that convert other languages to bytecode.

    1.2.3.1 History of java Around 1990 James Gosling, Bill Joy and others at Sun Microsystems began developing

    a language called Oak ,after an oak tree that stood outside Gosling's office, also went by

    the name Green and ended up later renamed as Java. They wanted it primarily to control

    Other languages e.g.: C,C++,

    Compile to bytecode

    Java source code

    Javac-compiler Outputs bytecode

    Independent Compilers

    JVM executes the bytecode

    Independent JVM

    Compile directly to local machine code executable

  • 7

    microprocessors embedded in consumer items such as cable set-top boxes,VCR's,

    toasters, and also for personal data assistants (PDA).

    To serve these goals, Oak needed to be: Platform independent (since multiple

    manufacturers involved), Extremely reliable ,compact.

    However, as of 1993, interactive TV and PDA markets had failed to take off. Then the

    Internet and Web explosion began, so Sun shifted the target market to Internet

    applications and changed the name of the project to Java.

    By 1994 Sun's Hot Java browser appeared. Written in Java in only a few months, it

    illustrated the power of applets, programs that run within a browser, and also the

    capabilities of Java for speeding program development.

    Riding along with the explosion of interest and publicity in the Internet, Java quickly

    received widespread recognition and expectations grew for it to become the dominant

    software for browser and consumer applications.

    However, the early versions of Java did not possess the breadth and depth of capabilities

    needed for client applications. For example, the graphics in Java 1.0 seemed crude and

    clumsy compared to mature software developed with C and other languages.

    Applets became popular and remain common but don't dominate interactive or

    multimedia displays on web pages. Many other plug-in types of programs also run within

    the browser environment.

    So Java has not succeeded at development of consumer applications. However, Java's

    capabilities grew with the release of new and expanded versions and it became a very

    popular language for development of enterprise, or middleware, applications such as on

    line web stores, transactions processing, database interfaces, and so forth.

  • 8

    Java has also become quite common on small platforms such as cell phones and PDAs.

    Java is now used in several hundred cell phone models. Over 600 million JavaCards,

    smart cards with additional features provided by Java, have been sold as of the summer of

    2004. [5]

    1.2.3.2 Justification of chosen language

    Java is the program of our choice to use in the creation of 3D solid graphics because it

    has features such as graphic packages (AWT, Swing, JAVA 2D).

    This allow us to be in full interaction with the jdk through java netbeans IDE.

    Another reason using java language is that it is secure and portable, hence, any type of

    operating system the user may have.

    1.2.4 Problem statement

    We have to draw a Bezier curve and changes according to mathematical concepts.

    We will try to move the curve from position 1 to position 2.

    1.2.5 Aims of the project

    Provide a basic practical and theoretical introduction to Bezier curve. To be familiar with 3D solid graphic creation. Extend our technical knowledge of programming language and techniques

    especially in Java.

    Introduce the facilities of Java netbeans IDE. Allow us to experience the difficulty in drawing the Bezier curve with different

    mathematics concepts.

    1.2.6 Objectives of the project

    3D solid graphics using Bezier curve have the following objectives:

  • 9

    Creation of 3D solid. Discuss the importance and use of Bezier curve. Improve the great importance of computer graphics in different domain. Introduce basic 3D terminology and 3D applications. Create, use and manipulate 3D shapes. Discuss the history of 3D graphics industry.

    1.2.7 Project scope

    We will create a 3D solid graphics with the help of Bezier curve.

    The created graphics can be used in various field such as computer aided

    design (CAD), engineering analysis, computer graphics, medical testing, project

    visualization and specific research.

    This project will be achieved using java 3D programming language with netbeans IDE

    as interface

    1.3 Methodology

    We have done documentation from the Internet.

    Textbook as methodologies during this project.

  • 10

    CHAPTER 2: LITERATURE REVIEW

    2.1 Introduction This chapter deals with some theoretical concepts that helps and used in 3D industry.

    Some of the terms will be explained in details according to their role in this project

    Others will be summarized.

    2.1.1 A solid is the states of matter characterized by resistance to deformation and

    changes of volume.

    2.1.2 Bezier curve: are parametric curves which are pretty much customizable and

    smooth; and they are suited for many applications.

    Bezier curves are used in computer graphics to produce curves which appear reasonably

    smooth at all scales (as opposed to polygonal lines, which will not scale nicely). General

    Bezier curves are interpolation equations. For example a Bezier curve generated with

    three collinear control points is a straight line segment. And a set of control points that

    are all at the same coordinate position produces a Bezier curve that is a single point.

    Here is a general function of Bezier curve:

    0

    ( ) (1 )n n

    n i iiii

    B t P t t=

    = (2)

    Pi are points of the curve, and n being the number of points.

    2.1.3 Java 3D : Java 3D is an addition to Java for displaying three-dimensional graphics.

    Programs written in Java 3D can be run on several different types of computer and over

    the internet.

  • 11

    The Java 3D class library provides a simpler interface than most other graphics libraries,

    but has enough capabilities to produce good games and animation.

    2.1.4 3D graphics: The field of computer graphics concerned with generating and

    displaying three-dimensional objects in a two-dimensional space (e.g., the display

    screen). Whereas pixels in a 2-dimensional graphic have the properties of position, color,

    and brightness, a 3-D pixels adds a depth property that indicates where the point lies on

    an imaginary Z-axis. When many 3-D pixels are combined, each with its own depth

    value, the result is a three-dimensional surface, called a texture. In addition to textures, 3-

    D graphics also supports multiple objects interacting with one another.

  • 12

    CHAPTER 3: ANALYSIS AND IMPLEMENTATION

    This chapter describes analysis of Bezier curve and its implementation. It is the very

    essence of the project and demands a greater share and the write-up than previous or

    subsequent chapters.

    3.1 Overview Bezier curve being our basic element have to be well understood, we have to provide full

    explanation on this curve by introducing some basic and general algorithms which are

    one of the ways used to draw the Bezier curve.

    Some analysis procedure will be undertaken through Fourier series followed by an

    implementation which will be more interesting and essence of this project including

    different modification applied to the drawn Bezier curve and providing 3D shapes.

    3.2 Analysis Three dimension curved lines and surfaces can be generated from mathematical functions

    which define the object or from a set of user specified data points.

    These mathematical concepts help us to draw a Bezier curves.

    Closed Bezier curves are generated by specifying the first and last control points

    At the same position, also specifying multiple control points at a single coordinate

    position gives more weight to that position.

    A single coordinate position may be input as two control points, and the resulting curve

    will be pulled nearer to this position.

    We fit a Bezier curve to any number of control points, but this requires the calculation of

    polynomial functions of higher degree.

    When complicated curves are to be generated, they can be formed by piecing several

    Bezier sections of lower degree together piecing together smaller sections also gives us

  • 13

    better control over the shape of the curve in small regions. Since Bezier curves pass

    through endpoints, it is easy to match curve sections (zero-order continuity).

    Bezier curve can be designed using different ways:

    Parametric equation deCasteljau Algorithm Bernstein algorithm

    We will not go through into detail of each methods but we have to look out the general

    algorithm.

    3.2.1 Constructive Bezier Curve Algorithm

    Consider the n+1 points P0,,Pn and connect the points into a polyline we will denote

    hereafter as the control polygon.

    Given points Pi, i = 0,...,n, our goal is to determine a curve g (t), for all values t [0,1].

    3.2.2 Basic Algorithm The objective here is to find points in the middle of two nearby points and iterate this

    until we have no more iteration. The new values of points will give us the curve. The

    famous Bezier equation is the exact formulation of this idea. Here is the algorithm:

    Step 1: Select a value t [0,1]. This value remains constant for the rest of the steps.

    Step 2: Set Pi[0] (t) = Pi, for i = 0,...,n.

    Step 3: For j= 0,..., n, set

    [ ] [ ] [ ]1 1

    1( ) (1 ) ( ) ( )j j j

    i i iP t t P t tP t

    = + For i = j,..., n.(3) Step 4: g (t) = Pn[n] (t)

  • 14

    1 11( ) ( ) (1 ) ( ) ( )

    n n nn n ng t P t t t tP t

    = = + (4)

    3.2.3 Special & General Cases Now, we have to introduce an expression for common, special cases that can be helpful

    in certain applications. The code of the article does not demonstrate any of them, but it

    uses the generalized formula.

    [ ]10 10

    ( ) (1 ) (1 ) (1 ) ....... , 0,11

    nn i i n n n

    i ni

    n nB t P t t P t P t t Pt t

    i

    =

    = = + + + (5) For the interest of simplicity and convention used in this section and code, it is better to

    represent this formula as:

    ( )0!( ) (1 )

    ! !

    nn i i

    ii

    nt P t ti n i

    =

    = (6) This equation tells us the formulation of the above algorithm (the mid-point iterations).

    It is very important that a whole algorithm could be summarized into a formula and a

    straightforward implementation would yield correct results. Here, n denotes the number

    of points and Pi denotes the points themselves.

    The factorial coefficients of the points are simply called the Bernstein basis functions,

    because of the name of the founder. Here are the special cases:

  • 15

    3.2.3.1 Linear Bezier curve There are two control points which are the endpoints for Bezier curve

    P0 and P1 and from those points a Bezier curve is drawn as a straight line between them.

    The equation becomes:

    ( ) ( ) ( ) [ ]0 1 0 0 1B t P t P P 1 t P t P, t 0,1 = + = + (7) 3.2.3.2 Quadratic Bezier curve There are three control points for quadratic Bezier curve, The first two control

    Points P0 and P2 are the two endpoints of the curve and the last control point is

    An intermediate point P1 which controls the direction of the tangents of the curve

    At both ends. This point is generally away from the curve itself.

    From these points a quadratic Bezier curve is drawn.

    The quadratic equation is given as:

    ( ) ( ) ( ) [ ]2 20 1 2B t 1 t P 2 t 1 t P t P , t 0,1= + + (8)

    3.2.3.3 Cubic Bezier curve

    There are four control points For cubic Bezier curves. The first two points P0 and P3 are

    the two endpoints of the curve, The two remaining ones are intermediate points

    P1 and P2. These intermediate points control the tangent and the curvature at both ends.

    From the defined points, a cubic Bezier curve is drawn

    The cubic equation is given by:

    ( ) ( ) ( ) ( )3 2 2 30 1 2 3B t 1 t P 3 t 1 t P 3t 1 t P t P, t [0,1]= + + + (9)

  • 16

    3.2.4 Parametric equation of degree n The parametric equation of a Bezier curve can be expressed into two different ways: as a

    closed form summation and in a matrix form.

    3.2.4.1 Summation form of a Bezier curve The parametric equation states that the location of any particular point is the sum of the

    product of each control point and the blending function.

    ],0

    ( ) ( ) , 0 , 1n

    i ni

    B t b t P i t=

    = (10) The blending function is given by

    , ( ) (1 ) , 0, ....n

    n i in i i

    b t t t i n = = (11) It is known as the Bernstein polynomials. By replacing the value of Bernstein

    polynomials in equation 1 we get the general equation of a Bezier curve

    0( ) (1 )

    nn i i

    ii

    nB t P t t

    i

    =

    = (12) 3.2.4.2 Matrix form of a Bezier curve We already have seen that the general equation of the Bezier curve is given by the form:

    0

    ( ) (1 )n

    n i ii

    i

    nB t P t t

    i

    =

    = (13) A Bezier curve having four control points, is drawn from the following parametric

    equation :

    ( ) ( ) ( ) ( ) [ ]3 2 2 30 1 2 3B t 1 t P 3 t 1 t P 3t 1 t P t P, t 0,1= + + + (14)

  • 17

    And the matrix form of this expression is written as:B(t)= (t3 t2 t 1)B

    0

    1

    2

    3

    PpPP

    (15)

    Where B is : (16)

    3.2.4 Analyzing the Bezier curve By Fourier series

    3.2.4.1. Overview The Bezier curve is a basic element of many computer graphic toolsets. This is not

    surprising, as it is easy to define and has well-understood mathematical properties. In this

    section, we apply the Discrete Fourier Transform to the construction of Bezier curves to

    gain more insight into their structure. As a Bezier curve is determined by its control

    polygon, this analysis is intimately linked to the Fourier analysis of the control polygon.

    3.2.4.2. Review We let P0, P1,., Pn be n+1 points in the plane. Let t be a parameter, normally an element

    of [0,1]. Then the Bezier curved defined by the points P0, P1,., Pn is defined by the

    vector equation:

    0

    ( ) (1 )n

    n n i ii i

    iB t C t t P

    == (17)

  • 18

    We recall that the polygon determined by the points P0, P1,..,Pn is called the control

    polygon of the curve. For instance, the line segments P0P1 and Pn-1Pn are tangents to the

    start, respectively, the end of the curve.

    The above equation results from an iterated process of subdividing line segments in the

    ratio t:(1-t), starting with the line segments Pn Pn+1, n = 0n.

    In the case of n = 4, for instance, we have

    ( ) ( ) ( ) ( ) [ ]3 2 2 30 1 2 3B t 1 t P 3 t 1 t P 3t 1 t P t P, t 0,1= + + +

    ( ( ) )0

    3 12 2 3

    2

    3

    1 3 (1 ) 3 (1 )

    Pp

    t t t t t tPP

    = (18)

    =

    = (19)

  • 19

    We recognize in the square matrix the inverse of the 44 binomial matrix. This is the

    matrix with general form

    B= (20)

    whose (j, k)th element is equal to C(j-1,k-1).

    It is instructive to see the effect of B-1 on the power basis (1,x,x2,..). In the 44 case, for

    instance, we have:

    = (21)

    We now introduce the Discrete Fourier Transform. If we let f0, f1fn be n+1 numbers,

    real or complex, then their Discrete Fourier Transform is the set of n+1 numbers

    2 / ( 1 )

    0

    ni j k n

    j ii

    f f e +=

    = (22)

    where i = 1 ,The numbers fj are in general complex numbers. We can invert this transformation as follows :

    2 / ( 1 )

    0

    11

    ni jk n

    i jj

    f f en

    +=

    = + (23)

  • 20

    We shall refer to the (n+1)x(n+1) matrix with (j,k)th element e-2ijk/(n+1) as the (discrete)

    Fourier matrix F. For instance, in the case n = 3, we have :

    = (24)

    =1/4 (25)

    We now apply the foregoing to Bezier curves in the plane. We observe that a point P in

    the plane can be regarded as a complex number, so that taking the Fourier transform of a

    set of points makes sense. We let j = e-2ij/(n+1) be a solution of the equation

    1 1 0nZ + = (26)

    0

    ( ) (1 )n

    n n i ii i

    iB t C P t t

    ==

    0

    1(1 )1

    ij

    n in nn i

    i ji o j

    C t t pn

    = == +

    0 0

    1 (1 )1

    n nn i i n i

    i j ji j

    C t t pn

    = =

    = +

  • 21

    ( )0 0

    1 (1 )1

    n n in n ij i j

    j ip C t t

    n

    = == +

    ( )0

    1 (1 ) *11

    nn

    j jj

    p t tn

    =

    = ++ (27) ( ) ((1 ) *1 )njPj t t t= +

    0(1 )

    nn i i n ik j

    iC t t

    ==

    0

    (1 )n

    n i n i ji i

    iC t t

    == (28)

    Hence

    0

    1( ) ( )1

    n

    j jj

    B t p P tn =

    = + (29) The Bezier curve with control polygon (P0,P1,,Pn). These basic Bezier curves have

    control polygons determined by the numbers ( ji ) and hence the geometry of these curves is determined by the geometry of the corresponding star-polygons.

    3.3 Implementation

    One strategy for implementing Bezier curves is to divide the curve into a fixed number of

    segments and then to pre-compute the values of the weighting functions for each of the

    segments. The greater the number of segments, the smoother the curve. Computing any

    given curve becomes a simple matter of using the four points and the precomputed

    weights to produce the end-points of the curve segments. We can optimize the process a

    bit. The curve touches each endpoint, so we can assume weights of 0 or 1 and neednt

  • 22

    compute weights for these points. Another optimization saves both time and space. By

    taking advantage of the symmetric nature of the Bezier equation, we can compute arrays

    of values for the first two of the weighting functions, and obtain values for the other two

    weights by indexing backwards into the arrays.

    To produce a display of a three-dimensional object, we must process the input data

    representation for the object through several procedures. These processing steps include

    transformation of the modeling and world-coordinate descriptions to viewing coordinates,

    then to device coordinates; identification of visible surfaces and the application of

    surface-rendering procedures. For some of these processes, we need information about

    the spatial orientation of the individual surface components of the object.

    3.3.1 Drawing a Bezier curve Here we have to make a java program which will draw a Bezier curve of different control

    point.

    When we run the program, the java applet will give an interface where the user will click.

    Figure 3: Java running environment

    Each click of the mouse button will be a control point of the curve and from those points;

    the java code will draw a Bezier curve according to those points.

  • 23

    If the user clicks twice it means that we have only two control points and from there a

    Linear Bezier curve is drawn.

    Figure 4 : Linear Bezier curve

    If the user add one more control point a quadratic Bezier curve is drawn.

    Figure 5 Quadratic Bezier curve

    When four control points are selected a cubic Bezier curve is drawn.

  • 24

    Figure 6 Cubic Bezier curve

    Closed Bezier curves are generated by specifying the first and last control points

    at the same position.

    Figure 7:Closed curve

    3.3.2 Bezier curve transformation

    Transformation of Bezier curve or objects in general refers to the Changes in orientation,

    size, and shape which are accomplished through geometric transformations that alter the

    coordinate descriptions of objects. The basic geometric transformations are translation,

    rotation, and scaling. Other transformations that are often applied to two dimensional

    objects include reflection and shear.

    This project will be concerned on translation of two dimension graphics.

    3.3.2.1 Translation basics

    A translation is applied to an object by repositioning it along a straight-line path

  • 25

    from one coordinate location to another. We translate a two-dimensional point by

    adding translation distances dx and dy to the original coordinate position P0(x0, y0) to

    move the point to a new position P1( x 1 , y1) .

    x1 = x + dx, y1= y +dy (30);

    The translation distance pair (dx,dy) is called a translation vector or shift vector.

    We can express the translation equations (1) as a single matrix equation by using column

    vectors to represent coordinate positions and the translation vector.

    This allows us to write the two-dimensional translation equations in the matrix form:

    P1=P0+T (31)

    Sometimes matrix-transformation equations are expressed in terms of coordinate row

    vectors instead of column vectors. In this case, we would write the matrix representations

    as P = (x y) and T= (dx, dy). Since the column-vector representation for a point is

    standard mathematical notation, and since many graphics packages also use the column-

    vector representation, we will follow this convention.

    Translation is a rigid body transformation that moves objects without deformation.

    That is, every point on the object is translated by the same amount. A straight Line

    segment is translated by applying the transformation equation (3) to each of the line

    endpoints and redrawing the line between the new endpoint positions.

    Polygons are translated by adding the translation vector to the coordinate position of each

    vertex and regenerating the polygon using the new set of vertex coordinates and the

    current attribute settings. Figure 8 illustrates the application of a specified translation

    vector to move an object from one position to another. Similar methods are used to

    translate curved objects.

    We translate Bezier curve by displacing the coordinate positions defining the curve, then

    we reconstruct the curve paths using the translated coordinate points.

  • 26

    CHAPTER 4 APPLICATION OF 3D SOLID GRAPHICS

    This chapter is concerned on the use of 3D solid graphics in a wide variety of industry.

    As we have seen earlier Computers have become a powerful tool for the rapid

    and economical production of pictures. There is virtually no area in which graphical

    displays cannot be used to some advantage, and so it is not surprising to find the use of

    computer graphics so widespread. Although early applications in engineering and science

    had to rely on expensive and cumbersome equipment, advances in computer technology

    have made interactive computer graphics a practical tool.

    Today, we find computer graphics used routinely in such diverse areas as Science,

    Engineering, medicine, business, industry, government, art, entertainment, advertising,

    education, and training.

    4.1 Three-dimensional solid graphics in medical industry

    The medical industry uses 3D solid graphics to create detailed models of organs.

    4.1.1 Three-Dimensional graphics in Radiotherapy

    Three-dimensional graphics in medical application is termed medical information

    system. The development of techniques for more efficient screening and managing with

    the potential for improving healthcare and provide benefits to patients.

    The contribution of three dimensional through scientific visualization to the area of

    medicine cannot be questioned. In particular, the application of volume rendering

    techniques to medical imaging, such as computed tomography (CT) and magnetic

    resonance (MR), provides the medical scientist with a powerful tool for the three-

    dimensional perception of anatomic and functional structures. The perception of three-

    dimensional relationships between different structures in the context of computed

    tomography is a very demanding and complex task. More specifically, in

  • 27

    Radiotherapy planning, it is very hard to determine whether a radiation beam will or not

    intersect an anatomic structure.

    An effective process of radiotherapy planning it is desirable that structures which

    are sensitive to radiation, so-called critical structures, be extracted so that they can be

    protected against possible damage.

    There some method to address this issue such as the precise segmentation of

    structures of interest, neural networks to separate white matter from grey matter within

    the human brain in magnetic resonance images, comparison of segmentation techniques

    applied to the human brain, probabilistic technique based on Bayesian classification and

    voxel histograms to segment brain images, combination of these

    three approaches to segment MR brain images.

    They use partial volume model, which analyses voxel neighborhood, shading

    correction, to account for low frequency intensity in homogeneities, and anatomical prior

    information deformable model techniques in the segmentation.

    All these methods are based upon the production of three-dimensional geometric solid

    4.1.2 Three-dimensional solid graphics in Biomechanics

    Complex parts of human skeleton are difficult to model using traditional

    mechanical techniques. Computational modeling techniques applied to the human body

    provide a possibility to analyze without interference in the human body.

    The growth and the development of computer simulation has been rapid and its uses have

    extended from the entertainment media to the airline and automotive industries, military,

    different branches of science like medicine, engineering, physics and certainly to

    education.

    To illustrate the potential that a combination of the knowledge from biology,

    engineering and computer graphics can have on the understanding of the development,

  • 28

    maintenance and repair of the skeleton and on the clinical management of bone disease is

    the essence in the biomechanical research.

    Biomechanics is the theory of how tissues, cells, muscles, bones, organs and the motion

    of them and their form and functions are regulated by basic mechanical proprieties.

    A comparison with engineering may help us to understand the principles that

    presumably guide the evolution of bone strength. As in many sciences, the integration of

    experimental and analytical model is critical to gain and understanding of the skeletal

    response to mechanical factors.

    Experiments provide insights and data, which can then be interpreted within the

    context of analytical frameworks. These investigations are greatly impacted by recent

    technological advances in imaging, computational mechanics, genetics and molecular

    biology. The integration of these techniques will provide important insight into skeletal

    development and disease.

    In medical application, attention of researchers has now turned toward using

    combined 3D reconstruction and virtual environment technologies to train clinicians and

    to help surgeons plan patient-specific, complex procedures like plastic surgery, surgery

    for trauma from accidents and reconstruction surgery. The 3D models are very useful in

    simulation of bone fractures and internal fixations with implants. These models are also

    important to understand how human musculoskeletal structures adapt to external forces

    disturbances. Because of the complexity of these structures and because not all the

    biological and anatomical data about them are known, there are many possibilities for

    how the system might work. Computational modeling techniques applied to the human

    body and skeleton provide a possibility to analyze without interference in the human

    body.

    4.2 Three-dimensional solid graphics in multimedia

    The term multimedia is used to describe home entertainment system and other

    electronic products and services, particularly interactive ones that combines text, sound,

  • 29

    video and like uses include virtual reality simulations, interactive television, commercial

    advertising and hypertext applications. It also known as a media that uses multiple forms

    of information system and information processing

    The movie industry uses 3D solid graphics to create and manipulate characters and

    objects for animated and real-life motion pictures. The video game industry uses them to

    create assets for video games.

    By using multimedia, in personal computing, software and applications that combine text,

    high quality sound, two and three-dimensional graphics, animation photo, images and full

    motion video.

    4.3 Three dimensional solid graphics in Graphical User Interface (GUI)

    Graphical User Interface is defined as the way of communicating with a computer

    that uses visual feedback to the user as much as possible. Features of a GUI include the

    use of icons to represent commands and options around the screen. By pointing to the

    appropriate icon or menu items and clicking a mouse button, various commands can be

    activated. It is also possible to use the mouse in drawing programs. Multiple window,

    icons, menus allow a computer setup to be utilized more efficiently

    Graphical User Interface is currently working on the zooming user Interface (ZUI)

    which is a logical advancement on the graphical user Interface, blending some three-

    dimensional movement with two-dimensional vector objects.

    The use of three-dimensional graphics has become increasingly common in

    mainstream operating system, but mainly been confined to creating attractive interfaces

    rather than for functional purposes only possible using three-dimensions.

    4.5 Three-dimensional solid graphics in Business graphics and presentation

    This application is a type of business software that refers the creation and manipulation of

    picture images in the computer. In such case the subject is typical called computer

    graphics it includes function for creating various types of charts and graphs and for

    inserting text in a variety of fonts.

  • 30

    4.6 Three-dimensional solid graphics in Computer Aided design (CAD) Computer Aided Design (CAD) is the use of computers to assist the design process.

    CAD programs exist for various types of design: architectural, engineering, electronics,

    roadways, and woven fabrics to name a few. CAD programs usually allow a structure to

    be built up from several re-usable 3-dimensional components. It is normally possible to

    generate engineering drawings to allow the final design to be constructed.

    Computer Aided Design may be performed in the traditional two-dimensional world or in

    the more revealing three-dimensional world.

    For example the swing path of a curved door might be best modeled in 3-D so the

    opening and closing path can be viewed from many perspectives - to more clearly see

    potential interferences.

    CAD is particularly used in the drafting engineering drawing of a part or product. To

    produce illustrations which summarize various kinds of data, 3D graphics are good tools

    for reporting more complex data

  • 31

    CHAPTER 5 CONCLUSION AND FUTURE WORK

    5.1 Conclusion The objective of this project was to create 3D solid graphics from Bezier curve. It

    have been interesting to develop this simple shapes and experiment with some of java

    netbeans features. Initially we introduced some preliminaries of Bezier curve and its

    history, after short demonstration on main algorithm we implemented a Bezier curve

    from a number of java codes.

    We have tried to move and rotate over an axis the drawn Bezier curve to create 3D solid

    graphics, the process have been a bit complicated but with our effort we successfully got

    some result. We discovered the great performance of java especially netbeans IDE.

    5.2 extension and future work Here we will discuss about some extension that can be done on this project as well as

    future works

    5.2.1 Improvements There are some small improvements that others may find suitable.

    We have created Program to generate a Bezier curve with only four control points but not

    a generalization as n points.

    Others may find that it more advantageous to make a general program which will draw

    Bezier curve of unlimited number of control points according to the user need.

    5.2.2 Extensions There are also some possible extensions that could be done on this project.

    As we created the 3D solid by rotating and translating the Bezier curve, shearing

    transformation could have been applied to Bezier curve.

    Another transformation which could have been applied to the Bezier curve is Scaling

    which alters the size of an object. This project can also be extended by transforming the

  • 32

    created 3D solid again by using the type of transformation that has been talked in the

    above paragraph.

    REFERENCES AND BIBLIOGRAPHY

    Reference

    [1] http://members.cox.net/mathmistakes/bezier.htm

    [2] http://particle.kth.se/~lindsey/javacourse/Book/part1/java/chapter1/what`s java.mht

    [3] http://particle.kth.se:80/~lindsey/javacourse/Book/part3/java/chapter24/index.html

    [4]http://particle.kth.se:80/~lindsey/javacourse/Book/part3/java/chapter1/supplements.mt

    [5]http://particle.kth.se:80/~lindsey/javacourse/Book/part3/java/chapter1/java history.mht

    [6] http://www.codeproject.com/KB/recipes/Beziercurves.aspx

    [7] http//:www.mi.sanu.ac.yo/vismath/barry/index.html

    [8] http//:www.webopidia.com/TERM/3.html

    [9]http//:www.netgraphics.sk/Bezier-curve4.html

    [10] http//en.wikipwdia.org/wiki/B%C3%A9zier-curve.html

    [11].www.math.ucla.edu/~baker/java/hoefer/Bezier.html

    [12] http://www.cs.pomona.edu/classes/cs51/Lectures/Lecture12/Lecture12_1.html

  • 33

    Bibliography

    1. DONALD HEARN & M.PAULIN BAKER ,COMPUTER GRAPHICS C VERSION

    SECOND EDITON

    2.Shreedhara K. S. & Indira S. P.,Construction of 3-D Objects Using 2-D CrossSectional

    Data and Curves, Department of CS&E, Universtity BDT College of Engineering

    Davangere 577004, Karnataka. India.

    3. Erik Hedenstrom(December 6, 2000),VISUALIZING GRAPHS USING JAVA3D

    4. Prof. Denis Zorin ,Bezier Curves and B-splines, Blossoming

    G22.3033-002: Topics in Computer Graphics: Lecture #2

    Geometric Modeling

    New York University

    Scribe: Kranthi K Gade

    5. Hong Zhang and Y. Daniel Liang,Computer Graphics Using Java 2D and 3D

    Pearson Prentice Hall

    Reviewer: Michael Grady

  • 34

    INDEX

  • 35

    CODE OF GENERATING BEZIER CURVE

    import java.applet.Applet ;

    import java.applet.Applet;

    import java.awt.*;

    public class ane extends Applet {

    Point[] p = new Point[5];

    int n = 0;

    int step = 50;

    public void paint(Graphics g) {

    int i;

    double t;

    double[] w = new double[5];

    Point old,current;

    g.setColor(Color.black);

    for(i=0;i

  • 36

    current = new Point((int)(w[0]*(double)p[0].x+ w[1]*(double)p[1].x+

    w[2]*(double)p[2].x+ w[3]*(double)p[3].x+w[4]*(double)p[4].x),

    (int)(w[0]*(double)p[0].y+ w[1]*(double)p[1].y+

    w[2]*(double)p[2].y+ w[3]*(double)p[3].y+w[4]*(double)p[4].y));

    g.drawLine(old.x,old.y, current.x,current.y);

    g.fillArc(old.x,old.y, current.x,current.y, step, ABORT);

    old = new Point(current.x, current.y);

    }

    }

    }

    public void init(){

    setBackground(Color.white);

    resize(600,600);

    }

    public boolean mouseDown(Event evt, int x, int y){

    if(n < 5) p[n++] = new Point(x,y);

    else n=0;

    repaint();

    return true;

    }

    }

  • 37

    CODE OF GENERATING BEZIER CURVE TRANSLATION

    import java.applet.Applet;

    import java.awt.*;

    public class Translation extends Applet {

    Point[] p = new Point[5];

    int n = 0;

    int step = 50;

    int dx=78;

    int dy=90;

    public void paint(Graphics g) {

    int i;

    double t;

    double[] w = new double[5];

    Point old,current;

    g.setColor(Color.black);

    for(i=0;i

  • 38

    w[4]=t*t*t*t;

    current = new Point((int)(w[0]*(double)p[0].x+ w[1]*(double)p[1].x+

    w[2]*(double)p[2].x+ w[3]*(double)p[3].x+w[4]*(double)p[4].x),

    (int)(w[0]*(double)p[0].y+ w[1]*(double)p[1].y+

    w[2]*(double)p[2].y+ w[3]*(double)p[3].y+w[4]*(double)p[4].y));

    g.drawLine(old.x,old.y, current.x,current.y);

    old = new Point(current.x, current.y);

    }

    }

    g.setColor(Color.black);

    for(i=0;i

  • 39

    old = new Point(current.x, current.y);

    }

    }

    }

    public void init(){

    setBackground(Color.white);

    resize(600,600);

    }

    public boolean mouseDown(Event evt, int x, int y){

    if(n < 5) p[n++] = new Point(x,y);

    else n=0;

    repaint();

    return true;

    }

    }

    CODE OF GENERATING A SOLID USING BEZIER CURVE.

    import java.applet.Applet;

    import java.awt.*;

    public class Solid extends Applet {

    Point[] p = new Point[5];

    int n = 0;

    int step = 50;

    int dx=78;

    int dy=90;

    public void paint(Graphics g) {

    int i;

  • 40

    double t;

    double[] w = new double[5];

    Point old,current;

    g.setColor(Color.black);

    for(i=0;i

  • 41

    for(i=0;i

  • 42

    resize(600,600);

    }

    public boolean mouseDown(Event evt, int x, int y){

    if(n < 5) p[n++] = new Point(x,y);

    else n=0;

    repaint();

    return true;

    }

    }