-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
54 lines (43 loc) · 1.06 KB
/
Copy pathvector.cpp
File metadata and controls
54 lines (43 loc) · 1.06 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
#include "vector.hpp"
#include <cmath>
namespace geometry
{
Vector::Vector(): x(0.0), y(0.0), z(0.0) {} // member initializer list
Vector::Vector(double x_, double y_, double z_) : x(x_), y(y_), z(z_) {}
Vector Vector::plus(const Vector& o) const
{
return Vector(x + o.x, y + o.y, z + o.z);
}
Vector Vector::minus(const Vector& o) const
{
return Vector(x - o.x, y - o.y, z - o.z);
}
Vector Vector::times(double s) const
{
return Vector(x * s, y * s, z * s);
}
double Vector::times(const Vector& o) const
{
return x * o.x + y * o.y + z * o.z;
}
double Vector::dot(const Vector& o) const
{
return times(o);
}
double Vector::length() const
{
return std::sqrt(x*x + y*y + z*z);
}
double Vector::magnitude() const
{
return length();
}
Vector Vector::cross(const Vector& o) const
{
return Vector (y * o.z - z * o.y, z * o.x - x * o.z, x * o.y - y * o.x);
}
void Vector::print(std::ostream& os) const
{
os << "(" << x << ", " << y << ", " << z << ")"; // "(1, 2.5, -3.14)"
}
}