MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

37
MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming

Transcript of MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Page 1: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

MEG 361 CADChapter 3

• Basic Concepts of GraphicsProgramming

Page 2: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Interactive shape manipulation plays a major role in

CAD/CAM/CAE

• Programming for graphics display on monitor is essential part of CAD/CAM/CAE software

Page 3: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Libraries

Graphics Software may be divided into two groups:

• device driver and

• graphics libraries.

Page 4: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Libraries

Application Program Device Driver

Input/output Devices

Graphics programming using graphics driver Directly, i. e.,"no libraries"

… More …

Page 5: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Libraries …

Device Driver is a set of machine-dependant codes that directly controls the display processing unit of a

graphics device so that the electron beam is cast at the desired location. Each device driver (machine-

dependant) has only a primitive capability, and so a graphics program written with such commands would be very long if any meaningful task to be performed. A

program with poor readability will result.

Page 6: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Libraries

… More …

Application Program Device Driver

Input/output Devices

Graphics programming using graphics libraries

Graphics Library

Page 7: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Libraries …

Graphics Libraries:• Similar to the math libraries in conventional programming,

the graphics library is a set of subroutines , each of which has a specific purpose. For example, a subroutine might draw a line or subroutine might draw a circle. The graphics library is built on top of the device driver as shown below. Each subroutine is created by using a supporting set of device driver commands, for example a subroutine for drawing a drawing a short straight-line segment, circle might be composed of series of device driver commands

… More …

Page 8: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Libraries …

Examples of Existing Graphics Libraries:• Core graphics provided in 1977, SIGGraph of

the Association of Computing Machinery (ACM)

• It does not provide enough commands to use all raster graphics systems.

• GKS was developed by (ISO) in about 1977.

… More …

Page 9: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Libraries …

Examples of Existing Graphics Libraries….:• Both CORE and GKS have some deficiencies with

regard to supporting dynamic display and versatile user interaction.

• OpenGL , set of libraries developed by Silicon Graphics Company, runs under MSwindows NT. It becomes the standard graphics library.

Page 10: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Coordinate Systems…

Basic tasks to display an image of an object on a graphics device:

• Specifying the location of all points on the object in space.

• Determining which locations on the display monitor to be occupied by those points .

… More …

Page 11: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Coordinate Systems…

Thus a coordinate system is necessary to provide a reference for specifying the location of a point both in space and on the monitor

… More …

Page 12: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Coordinate Systems…

1 Device coordinate system:

• Is used as the reference in defining a location on the display monitor.

• The origin of u-v-z axes is chosen arbitrary.

… More …

u

uu

vv

v

screen

z

Page 13: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Coordinate Systems…

2 Virtual device coordinate system:• Has the same origin.• The origin of u-v-z axes is in the lower left

part. Graphics programmer specifies a shape consistently regardless of the DCS.

… More …

uv

screen

Page 14: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Coordinate Systems…

Device coordinate system and

Virtual device coordinate system are 2-Dimesional

… More …

Page 15: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

World Coordinate System (WCS)

Is used to describe how the world

of interest looks like. It is 3-Dimesional.

… More …

It describes the locations and orientations of desks, chairs, and the blackboard if our world is a classroom.

Page 16: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Model Coordinate System (MCS)

Is used to describe the shape of a

part w.r.t. MCS attached to it. It is 3-Dimesional.

… More …

In MCS the coordinates of points on the part do not change their values even when the part is translated and/or rotated .

Page 17: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Model Coordinate System (MCS)…..

The location and orientation of

each part are then specified by WCS.

The coordinates of all points of the parts are obtained in WCS using transformation matrices.

… More …

Page 18: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Two Types of Projection

… More …

Perspective Projection Parallel Projection

Page 19: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Transformation bet. Coordinate

Systems

Page 20: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Window and Viewport Window defines the

region in space that will be projected onto the

display monitor so that any object outside the

space of the monitor will not be displayed

Parallel Projection

Viewport(s) is the area(s) on the display monitor where we want the projected image to appear.

… More …

Page 21: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Window and ViewportOpenGL Sample

Parallel Projection

Page 22: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Output primitives

are the graphics elements that can be displayed by a graphics libraray.

Line, Polygon, marker and Text are examples of output primitives.

Page 23: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Input …

Graphics program accepts points, lines,

or polygons as input in addition to numbers and text strings (e.,g; select a polygon among all the graphics elements on the display

“Locator” and “Button” are two types of physical device.

Page 24: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Graphics Input

“Locator” and “Button”

Locator transfers location of cursor to the graphics program (mouse ball)

Button” transfers action of user “on” or “off” at current cursor location (mouse button)

Page 25: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Representation of Cureves

In solid modeling and computer aided drafting systems, curve equation itself or its attributes (center point, radius,..) have to be stored .

Page 26: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

…Representation of Cureves

Curve equations: nonparametric Parametric,(x, y, z are related with

a parameter ( θ )

Page 27: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Nonparametric

Parametric

…Representation of CurevesCircle

0z,xRy

0z,0Ryx

22

222

,or

2πθ0

0z,θRsiny,θRcosx

Page 28: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Conic Sections

Page 29: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

See meg361_.....doc

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

x

y

P1 P2

P(t)=P1+(P2-P1)t

t=0

t=1

%parametric representation of curve%Line%----------------%example:% fro the position vector P1=[1;2]%P2=[4;3];plot the linet=0:.01:1;x=1+3*t;y=2+t;plot(x,y);grid;xlabel('x'),ylabel('y');axis([0 5 0 5]);

Page 30: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5

x

y

xmin

xmin segment of parabola

%meg361%parametric representation of %curve %parabola%----------------%example:% Generate the parabolic segment% in the first quadrant for 1<x<4%for the parabola given by% x=1*th^2, y=2*th, i;e; a=1%plot the segment of the parabolaa=1;xmin=1;xmax=4;thmin=sqrt(xmin/a);thmax=sqrt(xmax/a);th=thmin:(thmax-thmin)/101:thmax;x=a*th.^2;y=2*a*th;plot(x,y);grid;xlabel('x'),ylabel('y');axis([0 5 0 5]);

Page 31: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Linear TransformationTranslation

Page 32: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

Linear Transformation…Rotation…

Rotation @ x-axis

Page 33: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

…Linear Transformation……Rotation…

Rotation @ x-axis

Page 34: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

…Linear Transformation……Rotation…

Rotation @ x-axis...

Rot_x=

Page 35: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

…Linear Transformation……Rotation…

Similarly; Rotation @ y-axis...

Rot_y=

Page 36: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

…Linear Transformation……Rotation

Similarly; Rotation @ z-axis...

Rot_z=

Page 37: MEG 361 CAD Chapter 3 Basic Concepts of Graphics Programming.

…Linear Transformation…Graphics Library

Example: how transformation matrix is called