22#define gm3pos(x, y, z) ((gm3Pos){x, y, z})
31static inline void gm3_pos_set(
gm3Pos *p,
double x,
double y,
double z) {
42#define gm3_pos_magnitude(p) sqrt((p).x *(p).x + (p).y * (p).y + (p).z * (p).z)
50#define gm3_pos_distance(a, b) \
51 sqrt(pow((a).x - (b).x, 2) + pow((a).y - (b).y, 2) + pow((a).z - (b).z, 2))
59#define gm3_pos_from2(p, z) gm3pos((p).x, (p).y, z)
70#define gm3_pos_project_simple(p) gmpos((p).x / (p).z, (p).y / (p).z)
78static inline void gm3_pos_center(
gm3Pos *p,
const gm3Pos *va,
80 p->
x = (va->
x + vb->
x) / 2.0;
81 p->
y = (va->
y + vb->
y) / 2.0;
82 p->
z = (va->
z + vb->
z) / 2.0;
91static inline void gm3_pos_center3(
gm3Pos *p,
const gm3Pos *va,
93 p->
x = (va->
x + vb->
x + vc->
x) / 3.0;
94 p->
y = (va->
y + vb->
y + vc->
y) / 3.0;
95 p->
z = (va->
z + vb->
z + vc->
z) / 3.0;
103static inline void gm3_pos_substract(
gm3Pos *va,
const gm3Pos *vb) {
114static inline void gm3_pos_add(
gm3Pos *va,
const gm3Pos *vb) {
124static inline void gm3_pos_normalize(
gm3Pos *v) {
138#define gm3_pos_dot(a, b) ((a).x * (b).x + (a).y * (b).y + (a).z * (b).z)
146#define gm3_pos_cross(a, b) \
147 ((gm3Pos){(a).y * (b).z - (a).z * (b).y, (a).z * (b).x - (a).x * (b).z, \
148 (a).x * (b).y - (a).y * (b).x})
154#define gm3_pos_reset(p) memset(p, 0, sizeof(*p))
162static inline gm3Pos gm3_pos_centerN(
const gm3Pos *arr,
const size_t n) {
164 if (n == 0)
return res;
165 double dn = (double)n;
166 for (
size_t i = 0; i < n; i++) {
167 res.
x += arr[i].
x / dn;
168 res.
y += arr[i].
y / dn;
169 res.
z += arr[i].
z / dn;
204 snprintf(buffer,
sizeof(buffer),
"(gm3Pos){%.6g, %.6g, %.6g}", pos.
x, pos.
y,
206 gm_str_append(str, buffer);
int gmg_pos3(gmStr *str, gm3Pos pos)
Converts a gm3Pos struct to a string representation for debugging.
Definition position.h:202
void gm3_pos_mul(gm3Pos *res, const gm3Pos *trans)
Multiplies the components of a gm3Pos vector by the corresponding components of another gm3Pos vector...
Definition position.h:180
#define gm3_pos_magnitude(p)
Calculates the magnitude (length) of a gm3Pos vector.
Definition position.h:42
void gm3_pos_mul_scalar(gm3Pos *res, double s)
Multiplies the components of a gm3Pos vector by a scalar value.
Definition position.h:190
Defines a dynamic string structure and provides utility functions for its manipulation.
Represents a 3D position or vector.
Definition position.h:11
double y
Definition position.h:12
double z
Definition position.h:12
double x
Definition position.h:12
Represents a dynamic, heap-allocated string.
Definition str.h:21