Download presentation
Presentation is loading. Please wait.
Published byBlanche Daniel Modified over 8 years ago
1
Computer Graphics Lecture 17 3-D Transformations-I Taqdees A. Siddiqi cs602@vu.edu.pk
3
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)
4
3D Point
5
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
6
Pythagorus Theorem Distance between A and B = sqrt(dx*dx + dy*dy + dz*dz) where dx = Ax-Bx dy = Ay-By dz = Az-Bz
7
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).
8
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) :
9
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)
10
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.
11
Finding Unit Vector This is done by simply dividing each component by the length:
12
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)|
13
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.
14
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;
15
Operations between Points and Vectors point – point => vector point + point = point – ( - point) => vector vector – vector => vector
16
Operations between Points and Vectors vector + vector => vector point + vector => point point – vector = point + (-vector) => point
17
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
18
Example A vector of length 4 if multiplied by 2.5 Yields a vector of length 10 in the same direction as original
19
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
20
Vector Multiplication 1.Vectors can be multiplied in two ways: 1.Dot Product 2.Cross Product
21
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
22
Another definition of Dot Product A * B = |A| * |B| * cos(θ) Where θ is the angle between the two vectors
23
Properties of Cos(θ) cos(θ) > 0 if θ 270 o cos(θ) < 0 if θ is > 90 o and θ < 270 o cos(θ) = 0 if θ = 90 o or θ = 270 o
24
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.
26
we want to know if P is visible from the point-of-view (POV), or if P is “behind” the POV
27
Dot Product - Example Point3D pov; Vector3D povDir; Point3D test; Vector3D vTest float dotProduct;
28
Example cont… vTest.x = pov.x – test.x; vTest.y = pov.y – test.y; vTest.z = pov.z – test.z;
29
Example cont… dotProduct = vTest.x * povDir.x + vTest.y * povDir.y + vTest.z * povDir.z
30
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
31
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 )
32
This formula for A x B came from the determinate of order 3 of the matrix: | X Y Z | |A.xA.y A.z| |B.xB.y B.z|
33
Cross Product for physicists |A x B| = |A| * |B| sin(θ) Where θ is the angle between the two vectors
34
A Question A static set of 3D points or other geometric shapes on screen are not very interesting, are they ?
35
Transformations
36
The process of moving points in space is called transformation
37
Types of Transformation Translation Rotation Scaling Reflection Shearing
38
Translation Translation is used to move a point, or a set of points, linearly in space
39
Translation Distances t x, t y, t z For point P(x,y,z) after translation we have P′(x′,y′,z′) x′ = x + t x, y′ = y + t y, z′ = z + t z (t x, t y, t z ) is Translation vector
40
Now x′ = x + t x, y′ = y + t y and z′ = z + t z can be expressed as a single matrix equation: P′ = P + T Where P =P′ = T =
41
3D Translation Example you may want to move a point “3 meters east, -2 meters up, and 4 meters north.”
42
Steps for Translation Point3D point = (0, 0, 0) Vector3D vector = (10, -3, 2.5) Adding vector to point
43
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
45
Abbreviated as: P’ = T (t x, t y, t z ). P Homogeneous Coordinates
47
Computer Graphics Lecture 17
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.