Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Module 2-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

GEOMETRIC TRANSFORMATIONS

Geometric transformations are fundamental operations in computer


graphics that allow you to manipulate the position, orientation, and
size of objects in a 2D or 3D space. In 2D graphics, these
transformations are typically applied to points, lines, and shapes to
create various effects such as translation, rotation, scaling, and
reflection.

ATME COLLEGE OF ENGINEERING


COMMON GEOMETRIC TRANSFORMATIONS
• Translation: Moving an object from one position to another without changing its orientation or
size. This is done by adding or subtracting a constant value from the x and y coordinates of each
point.
• Rotation: Rotating an object around a fixed point (often the origin) by a certain angle. This
involves calculating new coordinates for each point based on the rotation angle.
• Scaling: Resizing an object by multiplying its coordinates by a scaling factor. Scaling can be
uniform (same factor for x and y) or non-uniform (different factors for x and y).
• Reflection: Flipping an object across a line (often the x-axis, y-axis, or a diagonal line). This
involves changing the sign of one coordinate while leaving the other unchanged.
• Shearing/Skewing: Distorting an object by shifting each point along one axis based on its
ATME COLLEGE OF ENGINEERING
position along the other axis. This can create slanted or skewed shapes.
ATME COLLEGE OF ENGINEERING

Fig 01: Refers to common geometric transformation


2D TRANSFORMATIONS

• Translation: This transformation moves an object from one position to


another. In 2D, translation involves adding or subtracting a constant value
from the x and y coordinates of each point of the object.

𝑷′ 𝒙 𝑷𝒙 + 𝒕𝒙
=
𝑷′ 𝒚 𝑷𝒚 + 𝒕𝒚
ATME COLLEGE OF ENGINEERING
2D TRANSFORMATIONS

• Rotation: Rotation transforms an object by a specified angle around a fixed


point. In 2D, this is typically done around the origin (0, 0). To rotate a point (x, y)
by an angle θ, the new coordinates (x', y') can be calculated as:

ATME COLLEGE OF ENGINEERING


2D TRANSFORMATIONS

• Rotation: Rotation transforms an object by a specified angle around a fixed


point. In 2D, this is typically done around the origin (0, 0). To rotate a point (x, y)
by an angle θ, the new coordinates (x', y') can be calculated as:
𝑥′=𝑥⋅cos(𝜃)−𝑦⋅sin(𝜃)
𝑦′=𝑥⋅sin(𝜃)+𝑦⋅cos(𝜃)

ATME COLLEGE OF ENGINEERING


2D TRANSFORMATIONS

• Rotation: Rotation transforms an object by a specified angle around a fixed


point. In 2D, this is typically done around the origin (0, 0). To rotate a point (x, y)
by an angle θ, the new coordinates (x', y') can be calculated as:
𝑥′=𝑥⋅cos(𝜃)−𝑦⋅sin(𝜃)
𝑦′=𝑥⋅sin(𝜃)+𝑦⋅cos(𝜃)

ATME COLLEGE OF ENGINEERING


2D TRANSFORMATIONS

• Scaling: Scaling changes the size of an object. In 2D, scaling can be uniform (same
scale factor for both x and y) or non-uniform (different scale factors for x and y). To
scale a point (x, y) by factors 𝑆x and 𝑆y , the new coordinates (x', y') can be calculated
ATME COLLEGE OF ENGINEERING

as:

𝑥′=𝑥⋅𝑆x
𝑦′=𝑦⋅𝑆y
• Reflection: Reflection flips an object over a line. In 2D, reflection is often
performed over the x-axis, y-axis, or a specified line. To reflect a point (x, y)
over the x-axis, the new coordinates (x', y') are (x, -y).
ATME COLLEGE OF ENGINEERING
Matrix Representation

ATME COLLEGE OF ENGINEERING


Matrix Representation

ATME COLLEGE OF ENGINEERING


HOMOGENEOUS COORDINATES
Homogeneous coordinates are a mathematical tool used in computer graphics to simplify
transformations and represent points at infinity. In 2D graphics, homogeneous coordinates are
represented as a three-element vector (x, y, w), where w is a scaling factor.

Homogeneous coordinates allow for transformations such as translation, rotation, scaling, and
perspective projection to be represented as matrix operations, which can simplify calculations
and make transformations more efficient. They are particularly useful for representing points at
infinity, which cannot be represented in Cartesian coordinates.

ATME COLLEGE OF ENGINEERING


ROTATION AND TRANSLATION

A small video on affine transformation

ATME COLLEGE OF ENGINEERING


OPENGL RASTER TRANSFORMATION
Rasterization is the process of converting vector graphics (such as geometric shapes and primitives) into a
raster image (pixels or dots) for display on a screen or for printing. In the context of computer graphics,
especially when using OpenGL or similar graphics APIs, rasterization is a critical step in rendering 2D and 3D
graphics.

Model Transformation:
• Converts vertices from model space (local object coordinates) to world space.
• Uses a model matrix to apply transformations like translation, rotation, and scaling.

View Transformation:
• Transforms vertices from world space to camera (view) space.
• Uses a view matrix that represents the camera's position and orientation.

Projection Transformation:
• Projects the vertices from view space to clip space.
• Uses a projection matrix (perspective or orthographic) to apply the perspective divide.

ATME COLLEGE OF ENGINEERING


OPENGL RASTER TRANSFORMATION
Viewport Transformation:
• Maps the normalized device coordinates (NDC) to window (screen) coordinates.
• Uses the viewport settings to determine the portion of the window where the final image will be
rendered.

Rasterization:
• Converts primitives (points, lines, triangles) into fragments.
• Fragments represent potential pixels on the screen, containing interpolated vertex data such as
color, depth, and texture coordinates.

Fragment Processing:
• Processes fragments using fragment shaders.
• Applies operations like texturing, lighting, and color blending.

ATME COLLEGE OF ENGINEERING


OPENGL RASTER TRANSFORMATION
In OpenGL, raster transformation refers to the process of transforming vertex data (such as position, color, and
texture coordinates) into fragments that can be rendered onto the screen. This process involves several stages,
including the transformation of vertices from object space to screen space, and eventually converting them into
fragments through rasterization. Here's an overview of the key steps involved:
1 2 3
4 5 6
7 8 9
10 11 12

If rotation applied for elements of pixel array in 900


3 6 9 12
2 5 8 11
1 4 7 10

If rotation applied for elements of pixel array in 900


12 11 10
9 8 7
6 5 4
ATME COLLEGE OF ENGINEERING
3 2 1
• glCopyPixels(xmin ,ymin, width, height, GL_COLOR)

• glReadPixels( xmin, ymin, width, height, GL_RGB, GL_UNSIGNED_BYTE, colorArray)

• glDrawPixels(width,height, GL_RGB, GL_UNSIGNED_BYTE, colorArray)

• glPixelZoom (sx, sy)

ATME COLLEGE OF ENGINEERING


OpenGL Geometric transformation functions
OpenGL, geometric transformations involve manipulating the position, orientation, and scale of objects in a 3D
space. These transformations are typically performed using matrices. OpenGL provides various functions to
facilitate these transformations, which are often used in conjunction with the GLM (OpenGL Mathematics)
library for convenience.

• Translation: glTranslate*(tx,ty,tz)
tz=0.0 for 2D
glm::mat4 model = glm::mat4(1.0f); // Identity matrix
model = glm::translate(model, glm::vec3(x, y, z)); // Translate by (x, y, z)

• Rotation: glRotate(theta, vx,vy,vz);


vz = 1.0
model = glm::rotate(model, glm::radians(angle), glm::vec3(axisX, axisY, axisZ)); // Rotate by 'angle'
around axis (axisX, axisY, axisZ)

• Scaling: glScale(sx,sy,sz);
sx=1.0
model = glm::scale(model, glm::vec3(scaleX, scaleY, scaleZ)); // Scale by (scaleX, scaleY, scaleZ)

ATME COLLEGE OF ENGINEERING


OpenGL Geometric transformation functions
• View Matrix: glMatrixMode(GL_MODELVIEW) (Projection Matrix)

• Transforms coordinates from view space to clip space.


• Can be a perspective or orthographic projection.

Matrix mode can be done with


• Color Mode
• Texture Mode

• Load Identity: glLoadIdentity();

• Matrix Multiplication: glMultMatrix*(otherElement16);

ATME COLLEGE OF ENGINEERING


ATME COLLEGE OF ENGINEERING
Three Dimensional Geometric Transformation
A three-dimensional position, expressed in homogeneous coordinates, is represented as a four-element
column vector. Thus, each geometric transformation operator is now a 4 × 4 matrix, which premultiplies a
coordinate column vector. In addition, as in two dimensions, any sequence of transformations is
represented as a single matrix, formed by concatenating the matrices for the individual transformations in
the sequence. Each successive matrix in a transformation sequence is concatenated to the left of previous
transformation matrices.

Three-Dimensional Translation
A position P = (x, y, z) in three-dimensional space is translated to a location P = (x` , y` , z` ) by adding
translation distances tx, ty, and tz to the Cartesian coordinates of P:

ATME COLLEGE OF ENGINEERING


Three Dimensional Geometric Transformation
Translation: A position P =(x, y, z) in three-dimensional space is translated to a location P`= (x` , y` , z`)
by adding translation distances tx, ty, and tz to the Cartesian coordinates of P:

three-dimensional translation operations in matrix form and the coordinate positions, P and P`, are
represented in homogeneous coordinates with four-element column matrices, and the translation operator
T is a 4 × 4 matrix:

ATME COLLEGE OF ENGINEERING


ATME COLLEGE OF ENGINEERING
Rotation:
Three-Dimensional Coordinate-Axis Rotations The two-dimensional z-axis rotation equations are easily
extended to three dimensions, as follows:

Parameter θ specifies the rotation angle about the z axis, and z-coordinate values are unchanged by this
transformation. In homogeneous-coordinate form, the three-dimensional z-axis rotation equations are

ATME COLLEGE OF ENGINEERING


Rotation:
For an x axis rotation

Acyclic permutation of coordinates the transformation equations for a y-axis rotation:

ATME COLLEGE OF ENGINEERING


Scaling: The matrix expression for the three-dimensional scaling transformation of a position
P=(x,y,z) relative to the coordinate origin is a simple extension of two-dimensional scaling. We just
include the parameter for z-coordinate scaling in the transformation matrix:

The three-dimensional scaling transformation for a point position can be represented as

Where scaling parameters sx, sy, and sz are assigned any positive values. Explicit expressions for the scaling
transformation relative to the origin are

ATME COLLEGE OF ENGINEERING


As some graphics packages provide only a routine that scales relative to the coordinate origin, we can always
construct a scaling transformation with respect to any selected fixed position(xf, yf, zf) using the following
transformation sequence:
• Translate the fixed point to the origin.
• Apply the scaling transformation relative to the coordinate origin
• Translate the fixed point back to its original position

ATME COLLEGE OF ENGINEERING


ATME COLLEGE OF ENGINEERING
ATME COLLEGE OF ENGINEERING

You might also like