-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormalise_vector.cpp
More file actions
56 lines (33 loc) · 1.4 KB
/
Copy pathnormalise_vector.cpp
File metadata and controls
56 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "geo_vector.h"
#include<iostream>
int main(void) {
//Defining a 3D point of displacement type
typedef point< quantity<length>, 3 , cartesian > Point3D;
//Creating Two P and Q points in 3D space
Point3D P(1 * meter, 9 * meter, 6 * meter);
Point3D Q(4 * meter, 5 * meter, 6 * meter);
//Constructing PQ vector with P as Initial point and Q as Terminal Point
geo_vector<length> PQ(P,Q);
std::cout<<"PQ : "<< PQ <<std::endl;
//Using magnitude function to determine the initial Magnitude of Vector PQ
std::cout<<"Magnitude of Vector PQ Before Normalisation : "<< PQ.magnitude() <<std::endl;
//Normalising vector PQ using normalize function
PQ.normalize();
std::cout<<"Normalized PQ : "<< PQ <<std::endl; //PQ after get normalise
std::cout<<"Magnitude of Vector PQ After Normalisation : "<< PQ.magnitude() <<std::endl;
/**********************
Alternate Way
geo_vector.h consist of a reset_magnitude() function
this function can be used to change the length of a vector to a passed length
since a unit vector have a length of one unit we use it like this
PQ.reset_magnitude(1*meter);
**********************/
return 0;
}
/* * * OUTPUT * * * * * * * * * * *
PQ : (3 m)i + (-4 m)j + (0 m)k
Magnitude of Vector PQ Before Normalisation : 5 m
Normalized PQ : (0.6 m)i + (-0.8 m)j + (0 m)k
Magnitude of Vector PQ After Normalisation : 1 m
* * * * * * * * * * * * * * * *
*/