联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2018-11-10 10:09

Lab Assignment 8 ENGO 333

1

Lab Assignment #8 (Bonus)

Where would we be after a couple of geometric transformations?

Using a Simple Matrix Class and Advanced Eigen Library

Bonus Marks: There are 3 bonus marks available for this in-lab assignment. This will count as 3% topup

on the final grade.

Due date: Submit the required files (see the end of this document) to Dropbox on D2L before 23:30 on

Friday, November 9, 2018.

Objective: Gain experience with operator overloading as member and friend functions; using a simple

Matrix class to perform geometric transformations on a vector of coordinates; using Eigen library in C++;

using MATLAB for reading files and plotting data

Completion: This lab can be completed either individually or in groups of 2 students. Questions

regarding this lab should be directed to the instructor or the TA during the lab hours. The extra time

before the deadline is meant for preparing the report.

1. Introduction

1.1. Latitude and Longitude

As you know, the geographic coordinates of every location on the Earth can be specified in a geographic

coordinate system using latitude and longitude (see Figure 1). “The latitude of a point is the angle

between the equatorial plane and the straight line that passes through that point and through the center of

the Earth. Lines joining points of the same latitude trace circles on the surface of Earth called parallels, as

they are parallel to the equator and to each other. The longitude of a is the angle east or west of a

reference meridian to another meridian that passes through that point.” [Source: Wikipedia] (Note: You

will see in your future ENGO courses, that this is only one definition of latitude/longitude depending on

what type of coordinate system you are using to map the Earth and/or other celestial objects!)

Figure 1. Geographic coordinates (latitude and longitude)

Lab Assignment 8 ENGO 333

2

1.2. Three-dimensional (3D) Rotation and Translation

Rotating an object can be done using rotation matrices which are 3-by-3 matrices; rotation around x-axis

(R1), rotation around y-axis (R2), rotation around z-axis (R3). Given a rotation angle, these rotation

matrices are defined as follows.

According to Euler's rotation theorem, any three-dimensional rotation may be described using three

angles. If the rotations are written in terms of rotation matrices R1, R2, and R3, then a general rotation R

can be written as:

Note that there are many other conventions for defining the sequence of rotations and the rotation angles

themselves.

Let's denote the coordinates of i’th point of an object as [xi, yi, zi]. So, if the coordinates of all the

points on an object are stored in a matrix, say A, we can denote this matrix as:

1 11

2 22

3 33

xyz

xyz A

xyz

=  MMM

The coordinates in A can be rotated by a rotation matrix R as follows,

( )

1 11

2 22

3 33

r

r rr

r rr

r

r rr

A RA

xyz

xyz A

xyz

Τ Τ = MMM

where [xri, yri, zri] is the outcome of rotating [xi, yi, zi] with matrix R.

Translating (shifting) the coordinates can be done using a simple vector summation. Suppose that you

shift a point with coordinates [100, 200, 1] meters with a translation vector of [10, -20, 15] meters.

Therefore, your point will move to the coordinates [110, 180, 16] meters.

1.3. Objective

In this assignment, you are provided with a text file containing the geographic coordinates of several

points on Canada border. A sample part of the text file is shown in Figure 2. The first column is longitude

Lab Assignment 8 ENGO 333

3

in degrees, the second column is latitude in degrees, and the last one is set to zero (as I eliminated the

elevation information).

-65.613617000 43.420273000 0.000000000

-65.619720000 43.418053000 0.000000000

-65.625000000 43.421379000 0.000000000

-65.636124000 43.449715000 0.000000000

-65.633057000 43.474709000 0.000000000

Figure 2. A sample part of the file “CanadaBorder.txt”

We are going to complete the “Matrix” class we developed in the previous lab by overloading some

operators, which will make arithmetic matrix operations more straightforward. Then, we are applying this

class to read the coordinates of Canada border points, and to rotate and move our country!!! Finally, we

will write the results to a file and display them using MATLAB.

We will repeat the exact same operations using the Eigen library instead of our own Matrix class.

2. Programming Tasks

In Microsoft Visual Studio, create a new solution called Lab8_Solution and a project named

Lab8_project. You can select the starting directly (Location) of the solution anywhere on your

computer.

Copy Lab8_main.cpp, Matrix_Functions.cpp, Matrix_Header.h provided along

with this document on D2L to the project directory (folder Lab8_Project). In VS, from the

solution explorer, add these files to the project. The file Lab8_main.cpp contains an empty

main() function along with some comments that may help you complete your program.

Use the instructions given in Lecture 10 to include the Eigen library to your program.

Task 1. Read the prototypes and definitions for operator[] and operator+ in the MatrixBI

class.

In your report, give examples to show how each version of these operators should be called from

main().

Then, write the definitions of all the overloaded versions of the operator* whose prototype can be

found in Matrix_Header.h.

Task 2. In the Matrix_Functions.cpp file, complete the implementations of the following

functions, which use the Eigen MatrixXd type.

// To read the data from a file and store them to a MatrixXd object

void Read_Mat(const string& filename, MatrixXd& m);

// To write the elements of a MatrixXd object to a file

void Write_Mat(int precision, const string& filename, MatrixXd& m);

// To create a 3D rotation matrix and return the result to a MatrixXd object

Lab Assignment 8 ENGO 333

4

MatrixXd Rotation_Mat( double thetax, double thetay, double thetaz, char

unit);

The function Read_Mat() behaves very much like the read() member function of MatrixBI.

The function Write_Mat() behaves very much like the print() member function of MatrixBI.

The function Rotation_Mat() behaves very much like the Rotation() function.

Task 3. In the main() function, perform the following tasks:

Read the data from file "CanadaBorder.txt" into an object of type MatrixBI

Rotate the coordinates in the matrix by 10 degrees counter-clock wise around the z-axis

Shift the coordinates (resulted from the previous step) 31 degrees to South and 42 degrees to East

Write the transformed coordinates (resulted from the previous step) to a file named

“NewCanada_MatrixBI.txt”

Task 4. In the main() function, continue performing the following tasks:

Read the data from file “CanadaBorder.txt” into an object of type MatrixXd

Rotate the coordinates in the matrix by 10 degrees counter-clock wise around the z-axis

Shift the coordinates (resulted from the previous step) 31 degrees to South and 42 degrees to East

Write the transformed coordinates (resulted from the previous step) to a file named

“NewCanada_Eigen.txt”

Task 5. Write a MATLAB script called “Lab8_script.m” to perform the following tasks:

Load the data in files “CanadaBorder.txt”, “NewCanada_MatrixBI.txt”, and

“NewCanada_Eigen.txt” to three matrices.

Plot the coordinates in these matrices in one figure (longitudes at x-axis and latitudes at y-axis).

Use different point markers and different colors for the coordinates in each matrix.

If your code works properly, then you should see the real shape of Canada from the coordinates in

“CanadaBorder.txt”. Then, the other two borders should exactly overlay each other, and

should still look like the shape of Canada, which is both rotated and translated.

Do you know the “new Canada” shape intersects with which actual countries? Use Google Maps

to make a guess (We won’t grade your answer to this question)

3. Reporting Tasks

Your lab report must describe what you did (and your developed codes both in C++ and MATLAB) for

all the above tasks and must include the figure produced at Task 5, as well as answers to any other

questions asked in the above tasks.

What to Submit

Please submit the followings via D2L:

The report file, which MUST be in PDF format.

Lab Assignment 8 ENGO 333

5

The following completed source files only:

o Matrix_Functions.cpp

o Lab8_main.cpp

o Lab8_script.m


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp