MATH 340 University of Maryland Wk 6 Homogeneous Coordinates Project

User Generated

pnzrqvbc

Mathematics

math 340

University of Maryland Global Campus

MATH

Description

Unformatted Attachment Preview

Math 340 Mini Project 2: Homogeneous Coordinates Overview As we are seeing, linear algebra comes up in a lot of applications. One of the prime applications for vectors and matrix transformations is the area of computer graphics and the related fields of computer vision, robotics, and image processing. If fact, one of the best reviews of linear algebra may be found in the appendix of the Computer Graphics textbook [4]. Basic operations in computer graphics include translations, rotations, and scaling. In this project, we’ll investigate how these may be combined into a single matrix (multiplication) operation through the use of homogeneous coordinates. Background In computer graphics [4] (as well as in robotics [5]) object positions can be defined using vectors. Thus, changes in position (translations and rotations) can then be defined as matrix operations on these vectors. Likewise, scaling (resizing) the object can be also defined via matrix operations. These operations are represented as, 𝑃! = 𝑃 + 𝑇 (Translation) (1) 𝑃! = 𝑅𝑃 (Rotation) 𝑃! = 𝑆𝑃 (Scaling) (2) (3) We see that the latter two of these operations are multiplications, while the first (translation) is a sum. Thus it is difficult to combine the three operations into a single matrix transformation. However, this combination may be achieved if the vectors are rewritten in homogeneous coordinates. In homogeneous coordinates, we add a third coordinate to a point (vector). Instead of being represented by a pair of numbers (𝑥, 𝑦)1, each point (vector) is represented as a triple (𝑥, 𝑦, 𝑤). Thus a point in 2D will be represented by the set of points {(𝑥, 𝑦, 𝑤)|𝑤 ≠ 0} and we say point points are equal (equivalent) if and only if one is a multiple of the other. For example, (2,3,6) and (4,6,12) represent the point in 2D. That is, each point has many different homogeneous coordinate representations. Also, at least one coordinate must be nonzero (that is, (0,0,0) is not allowed.) If " $ " $ the w coordinate is nonzero, we can divide through by it giving (# , # , 1). That is, (# , # , 1) " $ represents the same point as (𝑥, 𝑦, 𝑤) and the numbers # and # are called the Cartesian coordinates of the homogeneous point. Hence we generally represent the point (𝑥, 𝑦) in Cartesian 1 In this project, we’ll deal with two dimensional vectors for ease of visualization, but similar techniques apply to three dimensional vectors (for example, see [2].) coordinates as the triple (𝑥, 𝑦, 1) in homogeneous coordinates. The points with 𝑤 = 0 are called points at infinity and will not be discussed here. The advantage of homogeneous coordinates is that they allow us to combine the three operations above into a single matrix transformation. For example, the translation of (𝑥, 𝑦) by the vector (ℎ, 𝑘) (that is, (𝑥, 𝑦) is translated to (𝑥, 𝑦) + (ℎ, 𝑘) = (𝑥 + ℎ, 𝑦 + 𝑘)) may be represented as, 1 0 ℎ 𝑥 𝑥+ℎ E0 1 𝑘F G𝑦H = E𝑦 + 𝑘F (1′) 0 0 1 1 1 A counterclockwise rotation through an angle 𝜃 is given by multiplication by the matrix cos 𝜃 E sin 𝜃 0 − sin 𝜃 cos 𝜃 0 0 0F 1 (2′) And a scaling by s in the x direction and t in the y direction, is given by, 𝑠 0 0 E0 𝑡 0F 0 0 1 (3′) Hence, combinations of these three operations are simply products of matrices of these forms. Note that if the matrix is of the form, 𝑟%,% E𝑟',% 0 𝑟%,' 𝑟',' 0 𝑡" 𝑡$ F 1 where the upper 2 × 2 submatrix is orthogonal and thus preserves angles and lengths (scaling is one in all directions). Such transformations are called rigid-body transformations and are useful in robotics and other applications with no deformations (see [5] for more details). Example For example, the 3 × 3 matrix that corresponds to a scaling of one-half (0.5), a rotation of 90 degrees, and a translation of −1 in the x direction and by 2 in the y direction, is given by, 0 −0.5 −1 E0.5 0 2F 0 0 1 Here is the transformation applied to a (blue) rectangle in Matlab and the resulting (red) rectangle. Exercises and Explorations 1. [15] Verify that the operations (1), (2), and (3) are given by the matrix operations as described by (1’), (2’), and (3’). 2. [5] Prove the two successive 2D rotations are additive (and thus commutative), that is, show 𝑅(𝜃% ) ∙ 𝑅(𝜃' ) = 𝑅(𝜃% + 𝜃' ) [Hint: Recall the trig identities for sum of angles.] 3. [5] Matrix multiplication is generally not commutative, thus rotation in 3D are generally not commutative. Give an example of two rotations in opposite order that shows they are not commutative. [You do not need to give the matrices – you may simply describe the operations. For example, rotate the unit vector in the x direction, 45 degrees clockwise around the y axis, etc.] Give a drawing or plot of your results. 4. [10] Determine the 3 × 3 matrix that corresponds to a scaling of doubling in each direction, a rotation of 45 degrees, and a translation of 2 in the x direction and by −2 in the y direction. Plot your results using a rectangle or similar figure as shown in the example. You may use software or an online application to do this. 5. [15] (Explore) Investigate and demonstrate the use of software or an online application to demonstrate the properties of homogeneous transformations. Make your results as general as possible. For example, allow user input of rotation angle, scaling factor, and translation vector and demonstrate the result on a figure of your choice2. Demonstrate what happens if you change the order of these operations. 2 Another option for this part is to investigate the “rvctools” Matlab Toolbox from the QUT site [5]. Unfortunately, due to differences in the string parsing functions, this toolbox doesn’t seem to work in Octave, but your mileage may vary. Conclusion Sometime complicating a problem makes it simpler. In this case, adding a coordinate to our standard Cartesian coordinates to make them into homogeneous coordinates allows us to combine several operations (scaling, rotation, and translation) into a single matrix transformation. References 1. Wikipedia: “Homogeneous Coordinates”, https://en.wikipedia.org/wiki/Homogeneous_coordinates. 2. Linear Algebra and Its Applications, David C. Lay, Steven R. Lay, and Judi McDonald, Fifth Edition, Pearson, 2016. 3. Elementary Linear Algebra, Ron Larson, Cengage Learning, 2017. 4. Computer Graphics, Foley, vanDam, Feiner, and Hughes. Third Edition, Addison Wesley, 1993. 5. QUT Robot Academy (Online Resource), https://robotacademy.net.au/ Appendix Matlab code used in the example: % Define and draw a square x=[0 2 2 0 0]; y=[0 0 1 1 0]; plot(x,y,'-o'); axis([-6 6 -6 6]); % Change to homogeneous coordinates z=ones(1,5); H=[x;y;z]; % Define the matrix for the transformation T=[0 -0.5 -1;0.5 0 2;0 0 1] % Multiply to do the scaling, rotation, and translation R=T*H; % Recover the Cartesian coordinates for plotting x1 = R(1,:); y1 = R(2,:); hold on; plot(x1,y1,'-o');
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

View attached explanation and answer. Let me know if you have any questions.This is answer PDF I am uploading MATLAB and Latex code too

Math 340 Mini Project 2: Homogeneous
Coordinates
April 27, 2021

1

Verify that the operations (1), (2), and (3) are
given by the matrix operations as described
by (1’), (2’), and (3’).
• Proof the equivalence between (1) and (1’)
0
Let P~ =< x, y >0 , T~ =< h, k>0 . Then
P~ 0 
= P~ + T~ =<

 x + h, y + k > .
x+h
1 0 h x
For the homogeneous form 0 1 k  y  =  y + k 
1
1
0 0 1
So both opperation represent the same translation, which means they are
equivalent.

• Proof the equivalence between (2) and (2’)
Since (2) P~ 0 = P~ · T~ represents a 2D rotation process.Then if P~ =< x, y >0 ,
p~0 shall be < xcos(θ)
ycos(θ)

 >

 − ysin(θ), xsin(θ) +
xcos(θ) − ysin(θ)
cos(θ) −sin(θ) 0 x
From (2’) we have sin(θ) cos(θ) 0 y  = xsin(θ) + ycos(θ)
1
0
0
1
1
So both opperation represent the same rotation, which means they are
equivalent.
• Proof the equivalence between (3) and (3’)
Since (3) P~ 0 = ~s · p~ represents a scaling process.Then if P~ =< x, y >0 , p~0
shall be < sx, ty >

   
s 0 0 x
sx
where s, t are constants From (3’) we have 0 t 0 y  =  ty 
0 0 1
1
1
So both opperation represent the same scaling process, which means they
are equivalent.

1

2

Prove the two successive 2D rotations are additive

Proof:






cos(θ1 ) −sin(θ1 ) 0
cos(θ2 ) −sin(θ2 ) 0
Let R(θ1 ) = sin(θ1 ) cos(θ1 ) 0, R(θ2 ) = sin(θ2 ) cos(θ2 ) 0, then
0
1
0
0
1
 0

cos(θ1 )cos(θ2 ) − sin(θ1 )sin(θ2 ) −sin(θ1 )cos(θ2 ) − cos(θ1 )sin(θ2 ) 0
R(θ1 )·R(θ2 ) = sin(θ1 )cos(θ2 ) + cos(θ1 )sin(θ2 ) cos(θ1 )cos(θ2 ) − sin(θ1 )sin(θ2 ) 0
0
0
1
Because
cos(θ1 + θ2 ) = cos(θ1 )cos(θ2 ) − sin(θ1 )sin(θ2 )
sin(θ1 + θ2 ) = sin(θ1 )cos(θ2 ) + cos(θ1 )sin(θ2 )


cos(θ1 + θ2 ) −sin(θ1 + θ2 ) 0
R(θ1 ) · R(θ2 ) = sin(θ1 + θ2 ) cos(θ1 + θ2 ) 0 = R(θ1 + θ2 )
0
0
1

3

Matrix multiplication is generally not commutative, thus rotation in 3D ...


Anonymous
I use Studypool every time I need help studying, and it never disappoints.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4