0% found this document useful (0 votes)
2 views

Lecture 17

Lecture 17 covers 3-D transformations in computer graphics, defining 3D points, vectors, and their operations. It explains the concepts of distance, unit vectors, vector addition, scalar multiplication, dot and cross products, and various types of transformations such as translation. The lecture also introduces homogeneous coordinates for representing transformations in a matrix form.

Uploaded by

usmansaeed1512
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 17

Lecture 17 covers 3-D transformations in computer graphics, defining 3D points, vectors, and their operations. It explains the concepts of distance, unit vectors, vector addition, scalar multiplication, dot and cross products, and various types of transformations such as translation. The lecture also introduces homogeneous coordinates for representing transformations in a matrix form.

Uploaded by

usmansaeed1512
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 47

Computer Graphics

Lecture 17

3-D Transformations-I
Taqdees A. Siddiqi
[email protected]
Computer Graphics

Lecture 17

3-D Transformations-I
Taqdees A. Siddiqi
[email protected]
Definition of a 3D Point

 A 3-D point is similar to its 2D counterpart; we simply


add an extra component, Z, for the 3rd axis:
 P = (x,y,z)
3D Point
Distance between Two 3D Points

 The distance between two points (Ax,Ay,Az) and


(Bx,By,Bz) can be found by again using the pythagorus
theorem
Pythagorus Theorem

 Distance between A and B =


sqrt(dx*dx + dy*dy + dz*dz)
where
• dx = Ax-Bx
• dy = Ay-By
• dz = Az-Bz
Definition of a 3D Vector

 Like it's 2D counterpart, a vector can be thought of in


two ways: either a point at (x,y,z) or a line going from
the origin (0,0,0) to the point (x,y,z).
Length of vector

 To calculate the length of a vector we simply calculate


the distance between the origin and the point at
(x,y, z) :
Length of vector

length = | (x,y,z) – (0,0,0) |


= sqrt( (x-0)*(x-0) +
(y-0)*(y-0) +
(z-0)* (z-0) )
= sqrt(x*x + y*y + z*z)
Unit Vector

 Often in 3D computer graphics you need to convert a


vector to a unit vector, i.e. a vector that points in the
same direction but has a length of 1.
Finding Unit Vector

 This is done by simply dividing each component by the


length:
Finding Unit Vector
 Let (x,y,z) be our vector
 length = sqrt(x*x + y*y + z*z)
 Unit vector =
| x , y , z |
| length length length |
Where length = |(x,y,z)|
 Note that if the vector is already a unit vector then the
length will be 1, and the new values will be the same
as the old ones.
3D Vector Addition

Adding vector to point


point.x = point.x + vector.x;
point.y = point.y + vector.y;
point.z = point.z + vector.z;
Operations between Points and Vectors

 point – point => vector


 point + point =
point – ( - point) => vector
 vector – vector => vector
Operations between Points and Vectors

 vector + vector => vector


 point + vector => point
 point – vector =
point + (-vector) => point
Multiplying: Scalar Multiplication

 Multiplying a vector by a scalar ( a number with no units) :


 Vector.x = Vector.x * Scalar
 Vector.y = Vector.y * Scalar
 Vector.z = Vector.z * Scalar
Example

 A vector of length 4
 if multiplied by 2.5
 Yields a vector of length 10
 in the same direction as original
Example

 A vector of length 4
 If multiplied by -2.5 instead,
 Yields a vector of length 10;
 but in the direction opposite to original
Vector Multiplication

1. Vectors can be multiplied in two ways:


1. Dot Product
2. Cross Product
Dot Product

 The dot product of two vectors A & B is defined by the


formula:
 A*B= A.x * B.x
+ A.y * B.y
+ A.z * B.z
Another definition of Dot Product

A * B = |A| * |B| * cos(θ)


Where θ is the angle between the two vectors
Properties of Cos(θ)
cos(θ) > 0
if θ < 90o or θ > 270o
cos(θ) < 0
if θ is > 90o and θ < 270o
cos(θ) = 0 if θ = 90o or θ = 270o
Use of Dot Product

 If point of view is at (px,py,pz).


 and is looking along the vector (vx,vy,vz),
 we have a point P (x,y,z) in space.
 we want to know if P is visible from the point-of-view
(POV), or if P is “behind” the POV
Dot Product - Example

 Point3D pov;
 Vector3D povDir;
 Point3D test;
 Vector3D vTest
 float dotProduct;
Example cont…

 vTest.x = pov.x – test.x;


 vTest.y = pov.y – test.y;
 vTest.z = pov.z – test.z;
Example cont…

dotProduct =
vTest.x * povDir.x + vTest.y * povDir.y +
vTest.z * povDir.z
if(dotProduct > 0)
 point is “in front of “ POV
 else if (dotProduct < 0)
 point is “behind” POV
 else point is orthogonal to the POV direction
Cross Product
 for Vectors A, B
 A X B = (A.y * B.z – A.z * B.y, A.z * B.x – A.x *
B.z, A.x * B.y – A.y * B.x )
 This formula for A x B came from the determinate of
order 3 of the matrix:
| X Y Z|
|A.x A.y A.z|
|B.x B.y B.z|
Cross Product for physicists

 |A x B| = |A| * |B| sin(θ)


 Where θ is the angle between the two vectors
A Question

 A static set of 3D points or other geometric shapes on


screen are not very interesting, are they ?
Transformations
Transformations

 The process of moving points in space is called


transformation
Types of Transformation

 Translation
 Rotation
 Scaling
 Reflection
 Shearing
Translation

 Translation is used to move a point, or a set of points,


linearly in space
 Translation Distances tx, ty, tz
 For point P(x,y,z) after translation we have P′(x′,y′,z′)
 x′ = x + tx , y′ = y + ty , z′ = z + tz (tx, ty , tz) is Translation
vector
Now x′ = x + tx , y′ = y + ty
and z′ = z + tz can be expressed as a single matrix equation:
P′ = P + T

Where P = P′ = T=

 x  x'  tx 
 y  y ' t 
     y
 z   z '   t z 
3D Translation
Example

 you may want to move a point “3 meters east, -2


meters up, and 4 meters north.”
Steps for Translation

 Point3D point = (0, 0, 0)


 Vector3D vector =
(10, -3, 2.5)
 Adding vector to point
Steps for Translation

 point.x = point.x + vector.x;


 point.y = point.y + vector.y;
 point.z = point.z + vector.z;
 And finally we have translated point
Homogeneous
Coordinates
 x'  1 0 0 tx   x
 y '  0 1 0   
t y   y
   .
 z'  0 0 1 tz   z 
     
 1  0 0 0 1   1
Abbreviated as:
P’ = T (tx, ty , tz) . P
 x'  x  t x 
 y '  y  t 
   y

 z'  z  t z 
   
 1  1 
Computer Graphics
Lecture 17

You might also like