Hicasbcadepartment.files.wordpress.com



Unit-2

2D-Concepts

Basic transformation:

Transformation means changing some graphics into something else by applying rules. We can have various types of transformations such as translation, scaling up or down, rotation, shearing, etc. When a transformation takes place on a 2D plane, it is called 2D transformation.

Transformations play an important role in computer graphics to reposition the graphics on the screen and change their size or orientation.

Why they are used?

• Modelling

• Moving the objects to the desired location in the environment

• Multiple instances of a prototype shape

• Kinematics of linkages/skeletons – character animation

• Viewing

• Virtual camera: parallel and perspective projection

Types of Transformations

• Geometric Transformations

• Translation

• Rotation

• scaling

• Linear

• Linear (preserves parallel lines)

• Non-uniform scales, shears or skews

• Projection (preserves lines)

• Perspective projection

• Parallel projection

• Non-linear (lines become curves)

• Twists, bends, warps, morphs,

To perform a sequence of transformation such as translation followed by rotation and scaling, we need to follow a sequential process −

Translate the coordinates,

Rotate the translated coordinates, and then

Scale the rotated coordinates to complete the composite transformation.

To shorten this process, we have to use 3×3 transformation matrix instead of 2×2 transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra dummy coordinate W.

Matrix representation:

Matrix multiplication

The previous three lessons described the basic transformations that can be applied to models: translation, scaling, and rotation. These transformations can be combined to produce complex motion. But we need an easy and efficient way to combine these transformations. The solution is matrices!

This lesson will review the basics of matrix math and show you how to combine transformations using matrices. Matrices are used for almost all computer graphics calculations, including camera manipulation and the projection of your 3D scene onto a 2D viewing window.

Matrix

A point p can be transformed by multiplying it with the matrix M as follow:

Before going any further lets discuss in detail the previous formulations starting with the new definition of the point to be transformed. It is obvious that in order to perform the.

Composite Transformation

A composite transformation (or composition of transformations) is two or more transformations performed one after the other. Sometimes, a composition of transformations is equivalent to a single transformation. The following is an example of a translation followed by a reflection. The original triangle is the brown triangle and the image is the blue striped triangle. The brown striped triangle shows the intermediate step after the translation has taken place.

If a transformation of the plane T1 is followed by a second plane transformation T2, then the result itself may be represented by a single transformation T which is the composition of T1 and T2 taken in that order. This is written as T = T1∙T2.

Composite transformation can be achieved by concatenation of transformation matrices to obtain a combined transformation matrix.

A combined matrix −

[T][X] = [X] [T1] [T2] [T3] [T4] …. [Tn]

Where [Ti] is any combination of

● Translation

● Scaling

● Shearing

● Rotation

● Reflection

The change in the order of transformation would lead to different results, as in general matrix multiplication is not cumulative, that is [A].[B] ≠ [B].[A] and the order of multiplication. The basic purpose of composing transformations is to gain efficiency by applying a single composed transformation to a point, rather than applying a series of transformation, one after another.

For example, to rotate an object about an arbitrary point (Xp, Yp), we have to carry out three steps −

● Translate point (Xp, Yp) to the origin.

● Rotate it about the origin.

● Finally, translate the center of rotation back where it belonged.

[pic]

Translation Algorithm:

Translation refers to moving an object to a different position on screen.

Formula: X = x + tx

Y = y + ty

where tx and ty are translation coordinates

The OpenGL function is glTranslatef( tx, ty, tz );

General Pivot Point Rotation

For rotating object about the arbitrary point called pivot point, we need to apply following sequence of transformation.

1. Translate the object so that the pivot-point coincides with the coordinate origin.

2. Rotate the object about the coordinate origin with specified angle.

3. Translate the object so that the pivot-point is returned to its original position (i.e. Inverse of step-1).

A transformation sequence for rotating an object about a specified pivot point using the rotation matrix

|[pic] |Original Position of Object and Pivot Point |

|[pic] |Translation of Object so that Pivot Point is at Origin |

|[pic] |Rotation about Origin |

|[pic] |Translation of Object so that Pivot Point is Returned to original Position |

P' = T(xr, yr) . R([theta]) . T(-xr, -yr) . P

Rotation Algorithm:

Rotation refers to rotating a point.

Formula: X = xcosA - ysinA

Y = xsinA + ycosA,

A is the angle of rotation.

The above formula will rotate the point around the origin.

To rotate around a different point, the formula:

X = cx + (x-cx)*cosA - (y-cy)*sinA,

Y = cx + (x-cx)*sinA + (y-cy)*cosA,

cx, cy is centre coordinates,

A is the angle of rotation.

The OpenGL function is glRotatef (A, x, y, z).

Fixed point scaling:

As per usual phenomenon of scaling an object moves closer to origin when the values of scaling factor are less than 1. To prevent object from moving or changing its position while is scaling we can use a point that is would be fixed to its position while scaling which is commonly referred as fixed point (xf yf).

A scaling transformation alters size of an object. In the scaling process, we either compress or expand the dimension of the object.

Scaling operation can be achieved by multiplying each vertex coordinate (x, y) of the polygon by scaling factor sx and sy to produce the transformed coordinates as (x’, y’).

So, x’ = x * sx and y’ = y * sy.

The scaling factor sx, sy scales the object in X and Y direction respectively. So, the above equation can be represented in matrix form:

[pic]

Or P’ = S . P

Scaling process:

[pic]

Two-dimensional Viewing And Clipping

The two dimensional viewing is a transformation process of real world object into position point which is relative to the viewing volume, especially, the points behind the viewer.

[pic]

Scaling Algorithms

 Scaling refers to zooming in and out an object in different scales across axes.

Formula: X = x*sx

Y = y*sy, sx, sy being scaling factors.

The OpenGL function is glScalef(float x, float y, float z)

Viewing transformations:

1. The viewing transformation converts objects from their 3-dimensional camera-space coordinates into the appropriate 2-dimensional raster-space coordinates.

2. The camera coordinate system is a coordinate system with the camera at the origin, looking out over the positive z axis.

3. It is, essentially, the scene from the camera's point of view. The raster coordinate system is the space of the pixels on the monitor.

4. Connecting these two coordinate systems there is a special coordinate system known as the screen coordinate system.

5. The screen coordinate system is, conceptually, the same as the film plane of a camera.

6. It is usually best to consider both the screen coordinate system and the raster coordinate system to be two-dimensional, even though we know that RenderMan can output depth information.

7. The RenderMan Interface Specification has a rather complex viewing transformation. The interface has many calls which each set-up a small piece of the transformation.

8. Each of these values has a “reasonable” default, which is to say that if you don't set it, it will default to something which is probably appropriate, given the values that you have already set.

9. The viewing transformation has lots of controls, but typically they are not all used together. Rather, a couple important controls are set and the rest are let to default to their “logical” values.

10. The viewing transformation can be broken down into two pieces, the camera-to-screen projection and the screen-to-raster projection.

o The camera-to-screen projection flattens the 3-D world onto the 2-D screen.

o The screen-to-raster projection maps every point on the screen onto some output pixel.

Windowing transformation:

[pic]

A windowing system is a system for sharing a computer's graphical display presentation resources among multiple applications at the same time. In acomputer that has a graphical user interface (GUI), you may want to use a number of applications at the same time (this is called task).Windowing is the transforming co-ordinates from one space to another. It is used when scaling and transforming the view of a program. For example: when you zoom into an image, the original image data is transformed to fill the current screen. This is done through an area referred to as the “window”.

Clipping Operation:

Clipping is a computer graphics process to remove the lines, objects, or line segments, all of which are outside the viewing pane.

The clippings are categorized as

• Point clipping

Point clipping uses the clipping window and checks whether the given point is within the window or not, and based on it, decides the usage of minimum and maximum window coordinates.

[pic]

• Line clipping

The portion which is located outside the window is clipped and the remaining available is retained.

[pic]

[pic]

• Polygon clipping

Polygons are clipped based on the window; the portion which is inside the window is kept as it is and the outside portions are clipped.

[pic]

[pic]

After clipping

Figure to represent the polygon clipping

• Curve clipping

The curved line which is residing inside the box is left as it is and the outside portions are clipped.

• Text clipping

Various graphical techniques are used for text clipping; usually the text which is residing inside the box is retained and the other parts are clipped.

[pic]

Sutherland–Hodgman algorithm

The Sutherland–Hodgman algorithm is used for clipping polygons. It works by extending each line of the convex clip polygon in turn and selecting only vertices from the subject polygon that are on the visible side.

The algorithm begins with an input list of all vertices in the subject polygon. Next, one side of the clip polygon is extended infinitely in both directions, and the path of the subject polygon is traversed. Vertices from the input list are inserted into an output list if they lie on the visible side of the extended clip polygon line, and new vertices are added to the output list where the subject polygon path crosses the extended clip polygon line.

[pic]

A convex polygon and a convex clipping area are given. The task is to clip polygon edges using the Sutherland–Hodgman Algorithm. Input is in the form of vertices of the polygon in clockwise order.

Examples:

Input : Polygon : (100,150), (200,250), (300,200)

Clipping Area : (150,150), (150,200), (200,200),

(200,150) i.e. a Square

Output : (150, 162) (150, 200) (200, 200) (200, 174)

[pic]

Example 2

Input : Polygon : (100,150), (200,250), (300,200)

Clipping Area : (100,300), (300,300), (200,100)

Output : (242, 185) (166, 166) (150, 200) (200, 250) (260, 220)

[pic]

TextClipping

It is an extension used by Macintosh computers for strings of text, used since Mac OS 9 was released. When a string of text is selected and dragged to the desktop or everywhere of a Macintosh computer, the computer automatically converts it into a .textClipping file. The file formed can conveniently be dragged to any text box to replicate the exact text, including its formatting.[1]

Because of its legacy origins, the contents of textClipping files are not stored inside the actual data "fork" of the file, and the files cannot easily be shared between Macs or sent to other machines like an attachment. Opening the textClipping file in most applications will show a 0 byte empty data file. When OSX views or performs an action on a textClipping file, it performs a lookup of the file's resource fork where the contents are actually stored

TYPE OF TEXT CLIPPING 

1.Stroke

2.stardust

3.bitmap

STROKE : This method uses small line segments to generate a character we can built our own stoke method character generate by call through the line drawing algorithm.In this method a fixed pattern of line segments are used to generate the characters.There are 24 line segments. out of these 24 line segments the segments required to display for a particular character are highlighted.

STARDUST: This method of character generation is called stardust method because of  its characteristics appearance. a code conversion software is used in it to display a character from its 254 bits code. and the character quality is also poor. It is worst for curve shape character.

BITMAP: It is also known as the dot matrix because in this method character are character are represented by array of dots in the matrix form. It is 2D array that means having rows and columns. Each dot in the matrix is pixel. The value of pixel control the intensity of the pixel.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download