cs2405 - computer graphics laboratory. list of experiments 1.implementation of bresenhams algorithm...

18
CS2405 - COMPUTER GRAPHICS LABORATORY

Upload: anastasia-miller

Post on 21-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

CS2405 - COMPUTER GRAPHICS

LABORATORY

Page 2: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

LIST OF EXPERIMENTS

1. Implementation of Bresenhams Algorithm – Line, Circle, Ellipse.

2. Implementation of Line, Circle and Ellipse Attributes

3. Two Dimensional transformations - Translation, Rotation, Scaling, Reflection, Shear.

4. Composite 2D Transformations

5. Cohen Sutherland 2D line clipping and Windowing

6. Sutherland – Hodgeman Polygon clipping Algorithm

7. Three dimensional transformations - Translation, Rotation, Scaling

8. Composite 3D transformations

9. Drawing three dimensional objects and Scenes

10. Generating Fractal images

Page 3: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

List of Equipments and Components

1. Software : 1) Turbo C

2) Visual C++ with OPENGL

3) Any 3D animation software like 3DSMAX,

Maya, Blender

2. Operating system : WINDOWS 2000 / XP

Page 4: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Bresenham’s Algorithm – Line, Circle & Ellipse

• The Bresenham's line-drawing algorithm is based on drawing an approximation of the true line.

• The true line is indicated in bright color, and its approximation is indicated in black pixels.

• In this example the starting point of the line is (0, 0) and the ending point of the line at (9, 6).

Page 5: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Line, Circle and Ellipse Attributes

•Any parameter that affects the way a primitive is to be displayed is referred to as an attribute parameter.

Line attributes Circle attributes Ellipse attributes

Page 6: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

2D Transformations

• Transformaions are a fundamental part of computer graphics. Transformations are used to position objects, to shape objects, to change viewing positions, and even to change how something is viewed (e.g. the type of perspective that is used).

Translation

• Assume you are given a point at (x,y)=(2,1). Where will the point be if you move it 3 units to the right and 1 unit up? Ans: (x',y') = (5,2). How was this obtained? - (x',y') = (x+3,y+1). That is, to move a point by some amount dx to the right and dy up, you must add dx to the x-coordinate and add dy to the y-coordinate.

• What was the required transformation to move the green triangle to the red triangle? Here the green triangle is represented by 3 points

triangle = { p1=(1,0), p2=(2,0), p3=(1.5,2) }

Page 7: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Scaling

Suppose we want to double the size of a 2-D object. That is, we must specify how much to change the size along each dimension. Below we see a triangle and a house that have been doubled in both width and height (note, the area is more than doubled).

RotationBelow, we see objects that have been rotate by 25 degrees.

Page 8: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

•A sequence of transformations •calculate composite transformation matrix rather than applying individual transformations

• Composite two-dimensional translations• Apply two successive translations, T1 and T2

•Composite transformation matrix in coordinate form

Composite transformation

PM'P

PMM'P 12

PTTPTTP

ttTT

ttTT

yx

yx

)()('

),(

),(

1212

222

111

)tt,tt(T)t,t(T)t,t(T y2y1x2x1y1x1y2x2

Page 9: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

2D Clipping & windowing

Clipping Techniques in 2D Clipping in Two dimensions

Look at some possible cases.

1. Unclipped image

2. Clipped image

Page 10: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Window to Viewport Mapping

• Start with 3D scene, but eventually project to 2D scene

• 2D scene is infinite plane. Device has a finite visible rectangle. 

• Answer: map rectangular region of 2D device scene to device.

Window:rectangular region of interest in scene.

Viewport:rectangular region on device.

• Usually, both rectangles are aligned with the coordinate axes.

Page 11: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

• The Sutherland - Hodgman algorithm performs a clipping of a polygon against each window edge in turn. It accepts an ordered sequence of verices v1, v2, v3, ..., vn and puts out a set of vertices defining the clipped polygon.

•  This figure represents a polygon (the large, solid, upward pointing arrow) before clipping has occurred.

• The following figures show how this algorithm works at each edge, clipping the polygon.

• Clipping against the left side of the clip window.• Clipping against the top side of the clip window.• Clipping against the right side of the clip window.• Clipping against the bottom side of the clip window.

Sutherland - Hodgman Polygon Clipping

Page 12: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

3-D Transformations

• Transformations allow the developer to reposition, resize, and reorient models without changing the base values that define them.

Translation• It moves all the points in the Model3D

in the direction of the offset vector with

the OffsetX, OffsetY, and OffsetZ properties.

• For example, one vertex (2,2,2),

an offset vector of (0,1.6,1) would move that

vertex (2,2,2) to (2,3.6,3).

• The cube's vertex is still (2,2,2) in model

space, but now that model space has changed

its relationship to world space so that (2,2,2) in

model space is (2,3.6,3) in world space.

Page 13: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Scaling

• It changes the model's scale by a specified scale vector with reference to a center point. Specify a uniform scale, which scales the model by the same value in the X, Y, and Z axes, to change the model's size proportionally.

• For example, setting the transform's ScaleX, ScaleY, and ScaleZ properties to 0.5 halves the size of the model; setting the same properties to 2 doubles its scale in all three axes.

Page 14: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Rotation• Axis-angle rotations assume rotation about the origin if a value is not

specified for the CenterX, CenterY, and CenterZ properties on RotateTransform3D.

• As with scaling, it's helpful to remember that the rotation transforms the model's entire coordinate space.

• If the model was not created about the origin, or has been translated previously, the rotation might "pivot" about the origin instead of rotating in place.

Page 15: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Drawing three dimensional objects and Scenes

Page 16: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

• Animation is the rapid display of a

sequence of images to create an illusion 

of movement. The most common method

of presenting animation is as a motion

picture or video program.

• The bouncing ball animation consists of

these six frames(Flash). This animation

moves at 10 frames per second.

Page 17: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,

Generating Fractal images

• Self similarity between parts and overall features of the object is called fractal.

Page 18: CS2405 - COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,