Skip to content

Commit cc025c2

Browse files
clang-format and clang-tidy fixes for ff441e0
1 parent ff441e0 commit cc025c2

File tree

1 file changed

+67
-56
lines changed

1 file changed

+67
-56
lines changed

math/vector_cross_product.cpp

Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
/**
22
* @file
33
*
4-
* @brief Calculates the [Cross Product](https://en.wikipedia.org/wiki/Cross_product) and the magnitude of two mathematical 3D vectors.
4+
* @brief Calculates the [Cross
5+
*Product](https://en.wikipedia.org/wiki/Cross_product) and the magnitude of two
6+
*mathematical 3D vectors.
57
*
68
*
79
* @details Cross Product of two vectors gives a vector.
8-
* Direction Ratios of a vector are the numeric parts of the given vector. They are the tree parts of the
9-
* vector which determine the magnitude (value) of the vector.
10-
* The method of finding a cross product is the same as finding the determinant of an order 3 matrix consisting
11-
* of the first row with unit vectors of magnitude 1, the second row with the direction ratios of the
12-
* first vector and the third row with the direction ratios of the second vector.
13-
* The magnitude of a vector is it's value expressed as a number.
14-
* Let the direction ratios of the first vector, P be: a, b, c
15-
* Let the direction ratios of the second vector, Q be: x, y, z
16-
* Therefore the calculation for the cross product can be arranged as:
10+
* Direction Ratios of a vector are the numeric parts of the given vector. They
11+
*are the tree parts of the vector which determine the magnitude (value) of the
12+
*vector. The method of finding a cross product is the same as finding the
13+
*determinant of an order 3 matrix consisting of the first row with unit vectors
14+
*of magnitude 1, the second row with the direction ratios of the first vector
15+
*and the third row with the direction ratios of the second vector. The
16+
*magnitude of a vector is it's value expressed as a number. Let the direction
17+
*ratios of the first vector, P be: a, b, c Let the direction ratios of the
18+
*second vector, Q be: x, y, z Therefore the calculation for the cross product
19+
*can be arranged as:
1720
*
1821
* ```
1922
* P x Q:
@@ -28,11 +31,13 @@
2831
* 3rd DR, N: (a * y) - (b * x)
2932
*
3033
* Therefore, the direction ratios of the cross product are: J, A, N
31-
* The following C++ Program calculates the direction ratios of the cross products of two vector.
32-
* The program uses a function, cross() for doing so.
33-
* The direction ratios for the first and the second vector has to be passed one by one seperated by a space character.
34+
* The following C++ Program calculates the direction ratios of the cross
35+
*products of two vector. The program uses a function, cross() for doing so. The
36+
*direction ratios for the first and the second vector has to be passed one by
37+
*one seperated by a space character.
3438
*
35-
* Magnitude of a vector is the square root of the sum of the squares of the direction ratios.
39+
* Magnitude of a vector is the square root of the sum of the squares of the
40+
*direction ratios.
3641
*
3742
* ### Example:
3843
* An example of a running instance of the executable program:
@@ -46,68 +51,74 @@
4651
*/
4752

4853
#include <array>
49-
#include <cmath>
5054
#include <cassert>
55+
#include <cmath>
5156

5257
/**
5358
* @namespace math
5459
* @brief Math algorithms
5560
*/
5661
namespace math {
57-
/**
58-
* @namespace vector_cross
59-
* @brief Functions for Vector Cross Product algorithms
60-
*/
61-
namespace vector_cross {
62-
/**
63-
* @brief Function to calculate the cross product of the passed arrays containing the direction ratios of the two mathematical vectors.
64-
* @param A contains the direction ratios of the first mathematical vector.
65-
* @param B contains the direction ration of the second mathematical vector.
66-
* @returns the direction ratios of the cross product.
67-
*/
68-
std::array<double, 3> cross(const std::array<double, 3> &A, const std::array<double, 3> &B) {
69-
std::array<double, 3> product;
70-
/// Performs the cross product as shown in @algorithm.
71-
product[0] = (A[1] * B[2]) - (A[2] * B[1]);
72-
product[1] = -((A[0] * B[2]) - (A[2] * B[0]));
73-
product[2] = (A[0] * B[1]) - (A[1] * B[0]);
74-
return product;
75-
}
62+
/**
63+
* @namespace vector_cross
64+
* @brief Functions for Vector Cross Product algorithms
65+
*/
66+
namespace vector_cross {
67+
/**
68+
* @brief Function to calculate the cross product of the passed arrays
69+
* containing the direction ratios of the two mathematical vectors.
70+
* @param A contains the direction ratios of the first mathematical vector.
71+
* @param B contains the direction ration of the second mathematical vector.
72+
* @returns the direction ratios of the cross product.
73+
*/
74+
std::array<double, 3> cross(const std::array<double, 3> &A,
75+
const std::array<double, 3> &B) {
76+
std::array<double, 3> product;
77+
/// Performs the cross product as shown in @algorithm.
78+
product[0] = (A[1] * B[2]) - (A[2] * B[1]);
79+
product[1] = -((A[0] * B[2]) - (A[2] * B[0]));
80+
product[2] = (A[0] * B[1]) - (A[1] * B[0]);
81+
return product;
82+
}
7683

77-
/**
78-
* @brief Calculates the magnitude of the mathematical vector from it's direction ratios.
79-
* @param vec an array containing the direction ratios of a mathematical vector.
80-
* @returns type: double description: the magnitude of the mathematical vector from the given direction ratios.
81-
*/
82-
double mag(const std::array<double, 3> &vec) {
83-
double magnitude = sqrt((vec[0] * vec[0]) + (vec[1] * vec[1]) + (vec[2] * vec[2]));
84-
return magnitude;
85-
}
86-
} /// namespace vector_cross
87-
} /// namespace math
84+
/**
85+
* @brief Calculates the magnitude of the mathematical vector from it's
86+
* direction ratios.
87+
* @param vec an array containing the direction ratios of a mathematical vector.
88+
* @returns type: double description: the magnitude of the mathematical vector
89+
* from the given direction ratios.
90+
*/
91+
double mag(const std::array<double, 3> &vec) {
92+
double magnitude =
93+
sqrt((vec[0] * vec[0]) + (vec[1] * vec[1]) + (vec[2] * vec[2]));
94+
return magnitude;
95+
}
96+
} // namespace vector_cross
97+
} // namespace math
8898

8999
/**
90100
* @brief test function.
91101
* @details test the cross() and the mag() functions.
92102
*/
93103
static void test() {
94-
/// Tests the cross() function.
95-
std::array<double, 3> t_vec = math::vector_cross::cross({1, 2, 3}, {4, 5, 6});
96-
assert(t_vec[0] == -3 && t_vec[1] == 6 && t_vec[2] == -3);
104+
/// Tests the cross() function.
105+
std::array<double, 3> t_vec =
106+
math::vector_cross::cross({1, 2, 3}, {4, 5, 6});
107+
assert(t_vec[0] == -3 && t_vec[1] == 6 && t_vec[2] == -3);
97108

98-
/// Tests the mag() function.
99-
double t_mag = math::vector_cross::mag({6, 8, 0});
100-
assert(t_mag == 10);
109+
/// Tests the mag() function.
110+
double t_mag = math::vector_cross::mag({6, 8, 0});
111+
assert(t_mag == 10);
101112
}
102113

103114
/**
104115
* @brief Main Function
105-
* @details Asks the user to enter the direction ratios for each of the two mathematical vectors using std::cin
116+
* @details Asks the user to enter the direction ratios for each of the two
117+
* mathematical vectors using std::cin
106118
* @returns 0 on exit
107119
*/
108120
int main() {
109-
110-
/// Tests the functions with sample input before asking for user input.
111-
test();
112-
return 0;
121+
/// Tests the functions with sample input before asking for user input.
122+
test();
123+
return 0;
113124
}

0 commit comments

Comments
 (0)