Week 1
Week 1 – Mathematical Tasks
In the first lab from the first week, we got introduced to 3D Coordinate Geometry, mathematical theorems which can become advantageous in solving different queries in C++ (in general and for this module as well). Based on the concepts which we have approached during the lab, concepts like Minimum Distance from a Point or a Line to a Line, The Dot Product, 2D and 3D Straight Lines or Distance of a Point to a Plane we received some exercise which we had to do as a homework. For the first exercise on the paper sheet, I had to find the length of six different vectors using the following formula,
, the results can be seen in the subsequent picture:
The second exercise on the sheet asked to find the vectors between a pair of two vectors. This specific activity can be done using one of the Dot Product's formulas, to be more specific I have used a derivate of the formula because the exercise required the angle between the vectors, and the results can be seen in the following images:
The third exercise required the distance from a given point to a line defined by two vectors. Resolving this exercise I found out that the distance can be important because, in a game scene for example, with the help of these formulas the minimum distance from a ray to a centre of a sphere can be indicated easily. The results of the exercise are visible in the following pictures:
The fourth exercise requested to find the areas and the unit normal vectors of some triangular facets formed. To find the normal vector and the area, the cross product between the vectors representing the sides of a triangle strip needs to be found. As it can be seen in results for determining the cross product I have used Sarrus Rule:
The fifth and the final asked for finding the pierce point of two lines defined by 4 given vectors with the planes defines by the facets of the previous question. Having the planes already defined by the facets from question 4, the next step was to calculate the value of β for the fierce point for the plane of each facet takes one vector subtraction, two dot products and one division:
Week 1 – C++ Task (Vector3D Exercise)
In the second tutorial of the first week, we have received a tutorial about some basics in the C++ language and simple operations with vectors which was meant as a refresher. In the tutorial, we were given a class definition entitled "Vector3D" which was missing the definitions for the constructor of the function and for the add function, the one necessary in order two add 2 vectors. The first thing which I did was to split the declaration and the implementation onto a header and a CPP file. In the header of the project, I have declared the "Vector3D" function, also I have declared a simple print statement so I can print the result out. Another item which I have created was a CPP file, entitled "Main.cpp", a file which will hold my test vector. Following the declaration of variables and of the print statement, the next step was to overload the plus symbol in order to add all the vectors individually, the overload resolution is being used to determine the user-defined function to be called among all the functions. In the "Vector3D" file, the first thing which I have done was to initialize, following that I have done the arithmetic operators, for both addition and subtraction. An arithmetic operator computes the result of a distinct arithmetic operation and restores its conclusion. The last part of the exercise consists of creating the main function in the "Main.cpp", where I declared two 3D type vectors and where I called the two constructors which I have created earlier to add and subtract the vectors. The main reason behind using another CPP file for the main function was from a "code usage" (or better said the re-usage of the code) point of view.
No comments:
Post a Comment