-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vector3D.h
executable file
·206 lines (174 loc) · 6.06 KB
/
Vector3D.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* Class Vector3D header
* Created by Liad Elidan, 203380050, user:sharon1832
*/
#ifndef EX1_VECTOR3D_H
#define EX1_VECTOR3D_H
#include "iostream"
/* Constants */
#define ARRAY_SIZE 3
#define X_VAL 0
#define Y_VAL 1
#define Z_VAL 2
#define MINUS_VEC -1
#define POW_2 2
#define RESET 0
#define VECTOR_SIZE 3
#define MATRIX_SIZE 9
/**
* Class Vector3D
*/
class Vector3D
{
private:
double _x, _y, _z;
public:
/**
* Default constructor zeros the x,y,z.
*/
Vector3D ();
/**
* Vector constructor from 3 arguments.
* @param x is a double, x coordinate
* @param y is a double, y coordinate
* @param z is a double, z coordinate
*/
Vector3D (double x, double y, double z);
/**
* Vector constructor to build a vector with an array of size 3.
* @param data, double array of size 3.
*/
explicit Vector3D (double data[ARRAY_SIZE]);
/**
* Copy constructor
*/
Vector3D (const Vector3D&);
/**
* Overloading "+" operator between two vectors and returning a new one.
* @param other, Vector3D object.
* @return Vector3D object, which is the vector after adding the two vectors.
*/
Vector3D operator+(const Vector3D& other);
/**
* Overloading "-" operator between two vectors and returning a new one.
* @param other, Vector3D object.
* @return Vector3D object, which is the vector after subtracting the two vectors.
*/
Vector3D operator-(const Vector3D& other);
/**
* Overloading "+=" operator between a vector and another one.
* @param other, Vector3D object.
* @return Vector3D object, which is the vector after adding the vectors.
*/
Vector3D& operator+=(const Vector3D& other);
/**
* Overloading "-=" operator between a vector and another one.
* @param other, Vector3D object.
* @return Vector3D object, which is the vector after subtracting the vectors.
*/
Vector3D& operator-=(const Vector3D& other);
/**
* Overloading "=" operator between a vector and another one.
* @param other, Vector3D object.
* @return Vector3D object, which is a copy of the vector received.
*/
Vector3D& operator=(const Vector3D& other);
/**
* Overloading "+=" operator between a vector and a number.
* @param other, double& the number to add.
* @return Vector3D object, which is the vector plus the number received.
*/
Vector3D& operator+=(const double& other);
/**
* Overloading "-=" operator between a vector and a number.
* @param other, double& the number to subtract.
* @return Vector3D object, which is the vector minus the number received.
*/
Vector3D& operator-=(const double& other);
/**
* Overloading "-" to a vector.
* @return Vector3D object, which is the vector while having a -1 to all of it.
*/
Vector3D operator-();
/**
* Overloading "*" operator between a vector and a number.
* @param other, double& the number to multiply.
* @return Vector3D object, which is the vector while multiplied other to all of it.
*/
Vector3D operator*(const double& other);
/**
* Overloading "/" operator between a vector and a number.
* @param other, double& the number to divide.
* @return Vector3D object, which is the vector while divided other to all of it.
*/
Vector3D operator/(const double& other);
/**
* Overloading "*=" operator between a vector and a number.
* @param other, double& the number to multiply.
* @return Vector3D object, which is the vector multiplied by other.
*/
Vector3D& operator*=(const double& other);
/**
* Overloading "/=" operator between a vector and a number.
* @param other, double& the number to divide.
* @return Vector3D object, which is the vector divided by other.
*/
Vector3D& operator/=(const double& other);
/**
* Overloading "|" operator between two vectors. distance.
* @param other, Vector3D object.
* @return double , distance between the two vectors.
*/
double operator|(const Vector3D& other);
/**
* Overloading "*" operator between two vectors, return scalar multiplication.
* @param other, Vector3D object.
* @return double , scalar multiplication between the two vectors.
*/
double operator*(Vector3D& other);
/**
* Overloading "^" operator between two vectors. the angle.
* @param other, Vector3D object.
* @return double, the angle between them in radians.
*/
double operator^(Vector3D& other);
/**
* Overloading "[]" of a vector.
* @param index, an int number which is the index in the array of the vector.
* @return double&, which has the value in the appropriate array index.
*/
double& operator[] (const int &index);
/**
* Overloading "<<" the output to the ostream.
* @param out, std::ostream& variable.
* @param vector, Vector3D object.
* @return std::ostream& used in the output.
*/
friend std::ostream& operator<<(std::ostream& out, const Vector3D& vector);
/**
* Overloading ">>" the input to the istream.
* @param input, std::istream& variable.
* @param vector, Vector3D object
* @return std::istream& input, used in the input.
*/
friend std::istream& operator>>(std::istream& input, Vector3D& vector);
/**
* Overloading "*" operator between a number and a vector received.
* @param num, double, a number to multiply.
* @param other, Vector3D object received, the vector to be multiplied.
* @return Vector3D object, the vector after the multiplication.
*/
friend Vector3D operator * (double num, Vector3D& other);
/**
* Function to calculate the norm of a vector.
* @return double, the norm of the vector.
*/
double norm();
/**
* Function to calculate the distance between two vectors, the current one and one received.
* @param vector
* @return double, the distance between the vectors.
*/
double dist(const Vector3D& vector);
};
#endif //EX1_VECTOR3D_H