forked from 4ndrej/nether-earth-pc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
170 lines (118 loc) · 2.12 KB
/
Copy pathvector.cpp
File metadata and controls
170 lines (118 loc) · 2.12 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
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
#include "math.h"
#include "stdio.h"
#include "vector.h"
Vector::Vector()
{
x=0;
y=0;
z=0;
} /* Vector */
Vector::Vector(double nx,double ny,double nz)
{
x=nx;
y=ny;
z=nz;
} /* Vector */
Vector::Vector(const Vector &v)
{
x=v.x;
y=v.y;
z=v.z;
} /* Vector */
Vector Vector::operator+(const Vector &v)
{
Vector tmp;
tmp.x=x+v.x;
tmp.y=y+v.y;
tmp.z=z+v.z;
return tmp;
} /* operator+ */
Vector Vector::operator-(const Vector &v)
{
Vector tmp;
tmp.x=x-v.x;
tmp.y=y-v.y;
tmp.z=z-v.z;
return tmp;
} /* operator- */
Vector Vector::operator-(void)
{
Vector tmp;
tmp.x=-x;
tmp.y=-y;
tmp.z=-z;
return tmp;
} /* operator- */
Vector Vector::operator^(const Vector &v)
{
Vector res;
res.x=y*v.z-v.y*z;
res.y=z*v.x-v.z*x;
res.z=x*v.y-v.x*y;
return res;
} /* operator* */
double Vector::operator*(const Vector &v)
{
return x*v.x+y*v.y+z*v.z;
} /* operator* */
Vector Vector::operator*(double ctnt)
{
Vector res=*this;
res.x*=ctnt;
res.y*=ctnt;
res.z*=ctnt;
return res;
} /* operator* */
Vector Vector::operator/(double ctnt)
{
Vector res=*this;
res.x/=ctnt;
res.y/=ctnt;
res.z/=ctnt;
return res;
} /* operator/ */
bool Vector::operator==(const Vector &v)
{
if (x!=v.x ||
y!=v.y ||
z!=v.z) return false;
return true;
} /* operator== */
bool Vector::operator!=(const Vector &v)
{
if (x!=v.x ||
y!=v.y ||
z!=v.z) return true;
return false;
} /* operator!= */
double Vector::norma(void)
{
return sqrt(x*x+y*y+z*z);
} /* norma */
double Vector::normalize(void)
{
double n=norma();
if (n==0) return 0;
x/=n;
y/=n;
z/=n;
return n;
} /* normalize */
bool Vector::zero()
{
return (x==0 && y==0 && z==0);
} /* zero */
bool Vector::load(FILE *fp)
{
float t1,t2,t3;
if (3!=fscanf(fp,"%f %f %f",&t1,&t2,&t3)) return false;
x=t1;
y=t2;
z=t3;
return true;
} /* load */
bool Vector::save(FILE *fp)
{
fprintf(fp,"%.8f %.8f %.8f\n",float(x),float(y),float(z));
return true;
} /* save */