-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point and vector.cpp
48 lines (38 loc) · 915 Bytes
/
Point and vector.cpp
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
// vector structure
typedef long double dd;
struct point {
dd x, y, z;
point() {}
point(dd x1, dd y1, dd z1) {
x = x1;
y = y1;
z = z1;
}
dd operator * (const point &p) const {
return x*p.x+y*p.y+z*p.z;
}
point operator + (const point &p) const {
return point(x+p.x, y+p.y, z+p.z);
}
point operator - (const point &p) const {
return point(x-p.x, y-p.y, z-p.z);
}
point operator ^ (const point &p) const {
return point(y*p.z - p.y*z, p.x*z - p.z*x, x*p.y - p.x*y);
}
dd length() const {
return sqrtl(*this * *this);
}
void normalize() {
dd d = length();
x/=d;
y/=d;
z/=d;
}
point operator * (dd t) const {
return point(t * x, t * y, t * z);
}
point operator / (dd t) const {
return point(x / t, y / t, z / t);
}
};