0% found this document useful (0 votes)
23 views29 pages

Unit 3

Uploaded by

gotunamdevj11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views29 pages

Unit 3

Uploaded by

gotunamdevj11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

UNIT-3

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

2
Translation

• A translation moves an object to a different position on the screen.


You can translate a point in 2D by adding translation coordinate (t x, ty)
to the original coordinate (X, Y) to get the new coordinate (X’, Y’).

3
Translation(Continue..)

From the above figure, you can write that −

X’ = X + tx

Y’ = Y + ty

The pair (tx, ty) is called the translation vector or shift vector.

We can write it as −

P’ = P + T 4
Rotation
• In rotation, we rotate the object at particular angle θ (theta) from its
origin. From the following figure, we can see that the point P(X, Y) is
located at angle φ from the horizontal X coordinate with distance r
from the origin.
• Let us suppose you want to rotate it at the angle θ. After rotating it to
a new location, you will get a new point P’ (X’, Y’).

5
Rotation

6
Rotation
Using standard trigonometric the original coordinate of point P(X, Y) can be

represented as −

X=rcosϕ......(1) Y=rsinϕ......(2)

Same way we can represent the point P’ (X’, Y’) as -

x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ.......(3)

y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)

Substituting equation (1) & (2) in (3) & (4) respectively, we will get

x′=xcosθ−ysinθ

y′=xsinθ+ycosθ 7
Scaling
• To change the size of an object, scaling transformation is used. In the scaling
process, you either expand or compress the dimensions of the object. Scaling
can be achieved by multiplying the original coordinates of the object with the
scaling factor to get the desired result.
• Let us assume that the original coordinates are (X, Y), the scaling factors are
(SX, SY), and the produced coordinates are (X’, Y’). This can be
mathematically represented as shown below −

• X' = X . SX and Y' = Y . SY

• The scaling factor SX, SY scales the object in X and Y direction respectively.
8
3D Transformations
Translation
Continue..
Rotation
Rotation
Scaling
• The matrix expression for the scaling transformation of a position
P = (x, y, z) relative to coordinate origin can be written as:
Reflections
• The matrix expression for the reflection transformation of a position P = (x,
y, z) relative to x-y plane can be written as:

• Transformation matrices for inverting x and y values are defined similarly,


as reflections relative to yz plane and xz plane, respectively.
Shears
• The matrix expression for the shearing transformation of a
position P = (x, y, z), to produce z-axis shear, can be written as:
Shears
• Parameters a and b can be assigned any real values. The effect
of this transformation is to alter x- and y- coordinate values by
an amount that is proportional to the z value, while leaving the
z coordinate unchanged.
• Shearing transformations for the x axis and y axis are defined
similarly.
Clipping
Clipping
• Analytically calculating the portions of
primitives within the viewport

19
Why Clip?
• Bad idea to rasterize outside of framebuffer
bounds
• Also, don’t waste time scan converting pixels
outside window

20
Clipping
• The naïve approach to clipping lines:

for each line segment


for each edge of viewport
find intersection points
pick “nearest” point
if anything is left, draw it

• What do we mean by “nearest”?


• How can we optimize this?
21
Trivial Accepts
• Big optimization: trivial accept/rejects
• How can we quickly determine whether a line
segment is entirely inside the viewport?
• A: test both endpoints.
xmin maxx

ymax

ymin

22
Trivial Rejects
• How can we know a line is outside viewport?
• A: if both endpoints on wrong side of same
edge, can trivially reject line
xmin xmax

ymax

ymin

23
Cohen-Sutherland Line Clipping
• Divide viewplane into regions defined by
viewport edges
• Assign each region
x min
a 4-bit outcode:
x
max

1001 1000 1010


ymax

0001 0000 0010

ymin

0101 0100 0110


24
Cohen-Sutherland Line Clipping
• To what do we assign outcodes?
• How do we set the bits in the outcode?
• How do you suppose
x min we use them?
x
max

1001 1000 1010


ymax

0001 0000 0010

ymin

0101 0100 0110


25
Cohen-Sutherland Line Clipping
• Set bits with simple tests
x > xmax y < ymin etc.
• Assign an outcode to each vertex of line
– If both outcodes = 0, trivial accept
– bitwise AND vertex outcodes 1001together1000 1010
– If result  0, trivial reject y max

• As those lines lie on one


side of the boundary lines 0001 0000 0010

ymin
0101 0100 0110
26
Cohen-Sutherland Line Clipping
• If line cannot be trivially accepted or rejected,
subdivide so that one or both segments can be
discarded
• Pick an edge that the line crosses (how?)
• Intersect line with edge (how?)
• Discard portion on wrong side of edge and
assign outcode to new vertex
• Apply trivial accept/reject tests; repeat if
necessary
27
Cohen-Sutherland Line Clipping
• Outcode tests and line-edge intersects are
quite fast (how fast?)
• But some lines require multiple iterations:
– Clip top
– Clip left
– Clip bottom
– Clip right

28
Bit 1 = sign (y - yT) Bit 3 = sign (x – xR)
Bit 2 = sign (yB - y) Bit 4 = sign (xL - x)

• Left: y = m (xL - x1) + y1


• Right: y = m (xR - x1) + y1
• Top : x = (1/m) (yT - y1) + x1
• Bottom: x = (1/m) (yB - y1) + x1

29

You might also like