-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvec3.h
115 lines (94 loc) · 2.67 KB
/
vec3.h
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
// Mandexing: a manual indexing program for crystallographic data.
// Copyright (C) 2017-2018 Helen Ginn
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// Please email: vagabond @ hginn.co.uk for more details.
#ifndef __vagabond__vec3__
#define __vagabond__vec3__
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#include <string>
#include <vector>
struct vec3
{
double x;
double y;
double z;
};
struct vec2
{
double x;
double y;
};
double vec3_length(vec3 &vec);
void vec3_set_length(vec3 *vec, double length);
struct vec3 empty_vec3();
inline vec3 make_vec3(double x, double y, double z)
{
struct vec3 vec;
vec.x = x;
vec.y = y;
vec.z = z;
return vec;
}
vec3 make_randomish_axis();
inline vec2 make_vec2(double x, double y)
{
struct vec2 vec;
vec.x = x;
vec.y = y;
return vec;
}
inline bool vec2_less_vec2(vec2 x, vec2 y)
{
return x.x > y.x;
}
double vec3_sqlength(vec3 &vec);
struct vec3 vec3_add_vec3(vec3 &aVec, vec3 &bVec);
struct vec3 vec3_subtract_vec3(vec3 &to, vec3 &from);
double vec3_dot_vec3(vec3 &aVec, vec3 &bVec);
double vec3_angle_with_vec3(vec3 &aVec, vec3 &bVec);
double vec3_cosine_with_vec3(vec3 &aVec, vec3 &bVec);
vec3 vec3_cross_vec3(vec3 &aVec, vec3 &bVec);
double vec3_angle_from_three_points(vec3 &aVec, vec3 &bVec, vec3 &cVec);
double ewald_wavelength(vec3 &aVec);
vec3 vec3_from_string(std::vector<std::string> &components);
std::string computer_friendly_desc(vec3 &vec);
std::string vec3_desc(vec3 vec);
inline void vec3_min_each(vec3 *minVec, vec3 &aVec)
{
if (aVec.x < minVec->x) minVec->x = aVec.x;
if (aVec.y < minVec->y) minVec->y = aVec.y;
if (aVec.z < minVec->z) minVec->z = aVec.z;
}
inline void vec3_max_each(vec3 *maxVec, vec3 &aVec)
{
if (aVec.x > maxVec->x) maxVec->x = aVec.x;
if (aVec.y > maxVec->y) maxVec->y = aVec.y;
if (aVec.z > maxVec->z) maxVec->z = aVec.z;
}
inline void vec3_mult(vec3 *aVec, double mult)
{
aVec->x *= mult;
aVec->y *= mult;
aVec->z *= mult;
}
inline void vec3_set_length(vec3 *vec, double length)
{
double now = vec3_length(*vec);
vec3_mult(vec, length / now);
}
#endif /* defined(__vagabond__vec3__) */