-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathminivec.hh
55 lines (46 loc) · 932 Bytes
/
minivec.hh
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
#pragma once
#include <math.h>
#include <iostream>
struct Point
{
Point() : x{0}, y{0}, z{0}
{}
Point(double x_, double y_, double z_) : x(x_), y(y_), z(z_)
{}
double x, y, z;
};
inline std::ostream& operator<<(std::ostream& os, const Point& p)
{
os << '(' << p.x << ", " << p.y << ", " << p.z <<')';
return os;
}
struct Vector
{
Vector() : x{0}, y{0}, z{0} {}
Vector(double x_, double y_, double z_) : x(x_), y(y_), z(z_)
{}
Vector(const Point& a, const Point& b) : Vector(b.x - a.x, b.y - a.y, b.z - a.z)
{
}
double x, y, z;
double length() const
{
return sqrt(x*x + y*y + z*z);
}
void norm()
{
double l = length();
x/=l;
y/=l;
z/=l;
}
double inner(const Vector& b) const
{
return x*b.x + y*b.y + z*b.z;
}
};
inline std::ostream& operator<<(std::ostream& os, const Vector& p)
{
os << '(' << p.x << ", " << p.y << ", " << p.z <<')';
return os;
}