1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/geo.h Mon Oct 14 13:02:19 2013 +0000
1.3 @@ -0,0 +1,64 @@
1.4 +/*
1.5 + * Geometric operations.
1.6 + *
1.7 + * Copyright (C) 2013 Paul Boddie
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or modify
1.10 + * it under the terms of the GNU General Public License as published by
1.11 + * the Free Software Foundation; either version 2 of the License, or
1.12 + * (at your option) any later version.
1.13 + */
1.14 +
1.15 +#ifndef __GEO_H__
1.16 +#define __GEO_H__
1.17 +
1.18 +#include <math.h>
1.19 +#include "bool.h"
1.20 +
1.21 +typedef union
1.22 +{
1.23 + struct { double x, y, z; };
1.24 + double axis[3];
1.25 +} vectorf;
1.26 +
1.27 +double within(double value, double mag);
1.28 +bool vectorf_null(const vectorf *in);
1.29 +void vectorf_reset(vectorf *in);
1.30 +void vectorf_cross(const vectorf *in1, const vectorf *in2, vectorf *out);
1.31 +double vectorf_dot(const vectorf *in1, const vectorf *in2);
1.32 +double vectorf_mag(const vectorf *in);
1.33 +void vectorf_normalise(vectorf *in, vectorf *out);
1.34 +void plane_rotate(vectorf *in1, vectorf *in2, double angle);
1.35 +void vectorf_negate(vectorf *in, vectorf *out);
1.36 +double vectorf_direction(vectorf *in);
1.37 +double vectorf_elevation(vectorf *in);
1.38 +void vectorf_polar(double direction, double elevation, vectorf *out);
1.39 +void vectorf_convert(const vectorf *in, const vectorf *devicex, const vectorf *devicey, const vectorf *devicez, vectorf *out);
1.40 +void vectorf_convert_into(const vectorf *in, const vectorf *x, const vectorf *y, const vectorf *z, vectorf *out);
1.41 +double vectorf_tilt_in_plane(const vectorf *in, const vectorf *x, const vectorf *y);
1.42 +double vectorf_tilt_in_plane_with_axis(const vectorf *in, const vectorf *x, const vectorf *y, const vectorf *z);
1.43 +void vectorf_rotate_in_space(const vectorf *in, const vectorf *x, const vectorf *y, const vectorf *z, double angle, vectorf *out);
1.44 +
1.45 +#define degrad(x) ((x) * M_PI / 180.0)
1.46 +#define raddeg(x) ((x) * 180.0 / M_PI)
1.47 +
1.48 +#define fdiv(x, y) (floor((int) ((x) / (y))))
1.49 +
1.50 +/* Get the closest number at the given resolution. */
1.51 +
1.52 +#define closest(x, res) (((int) (x) / (res)) * (res))
1.53 +
1.54 +/* Get the maximum and minimum of the given numbers. */
1.55 +
1.56 +#define max(x, y) ((x) >= (y) ? (x) : (y))
1.57 +#define min(x, y) ((x) <= (y) ? (x) : (y))
1.58 +
1.59 +/* Get the sign of a number. */
1.60 +
1.61 +#define sign(x) ((x) == 0 ? 0 : (x) < 0 ? -1 : 1)
1.62 +
1.63 +/* Eliminate noise using the given threshold. */
1.64 +
1.65 +#define noise(x, y) (fabs(x) < (y) ? 0 : (x))
1.66 +
1.67 +#endif /* __GEO_H__ */