-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.cpp
More file actions
executable file
·51 lines (38 loc) · 954 Bytes
/
Vector.cpp
File metadata and controls
executable file
·51 lines (38 loc) · 954 Bytes
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
#include <math.h>
#include <iostream>
#include "Vector.h"
float Vector::magnitude() {
return sqrtf(x*x + y*y + z*z);
};
Vector Vector::normalize() {
if (this->magnitude() == 0)
return *this;
return *this / this->magnitude();
};
Vector Vector::cross(Vector v) {
return Vector(y*v.z - v.y*z, v.x*z - x*v.z, x*v.y - v.x*y);
};
float Vector::dot(Vector v) {
return x*v.x + y*v.y + z*v.z;
};
Vector Vector::operator + (Vector v) {
return Vector(x + v.x, y + v.y, z + v.z);
};
Vector Vector::operator - (Vector v) {
return Vector(x - v.x, y - v.y, z - v.z);
};
Vector Vector::operator * (Vector v) {
return Vector(x * v.x, y * v.y, z * v.z);
};
Vector Vector::operator / (Vector v) {
return Vector(x / v.x, y / v.y, z / v.z);
};
Vector Vector::operator * (float c) {
return Vector(c*x, c*y, c*z);
};
Vector Vector::operator / (float c) {
return Vector(x/c, y/c, z/c);
};
int main(int argc, char* argv[]) {
return 0;
};