paul@0 | 1 | /* |
paul@0 | 2 | * Geometric operations. |
paul@0 | 3 | * |
paul@0 | 4 | * Copyright (C) 2013 Paul Boddie |
paul@0 | 5 | * |
paul@0 | 6 | * This program is free software; you can redistribute it and/or modify |
paul@0 | 7 | * it under the terms of the GNU General Public License as published by |
paul@0 | 8 | * the Free Software Foundation; either version 2 of the License, or |
paul@0 | 9 | * (at your option) any later version. |
paul@0 | 10 | */ |
paul@0 | 11 | |
paul@0 | 12 | #ifndef __GEO_H__ |
paul@0 | 13 | #define __GEO_H__ |
paul@0 | 14 | |
paul@0 | 15 | #include <math.h> |
paul@0 | 16 | #include "bool.h" |
paul@0 | 17 | |
paul@0 | 18 | typedef union |
paul@0 | 19 | { |
paul@0 | 20 | struct { double x, y, z; }; |
paul@0 | 21 | double axis[3]; |
paul@0 | 22 | } vectorf; |
paul@0 | 23 | |
paul@0 | 24 | double within(double value, double mag); |
paul@0 | 25 | bool vectorf_null(const vectorf *in); |
paul@0 | 26 | void vectorf_reset(vectorf *in); |
paul@0 | 27 | void vectorf_cross(const vectorf *in1, const vectorf *in2, vectorf *out); |
paul@0 | 28 | double vectorf_dot(const vectorf *in1, const vectorf *in2); |
paul@0 | 29 | double vectorf_mag(const vectorf *in); |
paul@0 | 30 | void vectorf_normalise(vectorf *in, vectorf *out); |
paul@0 | 31 | void plane_rotate(vectorf *in1, vectorf *in2, double angle); |
paul@0 | 32 | void vectorf_negate(vectorf *in, vectorf *out); |
paul@0 | 33 | double vectorf_direction(vectorf *in); |
paul@0 | 34 | double vectorf_elevation(vectorf *in); |
paul@0 | 35 | void vectorf_polar(double direction, double elevation, vectorf *out); |
paul@0 | 36 | void vectorf_convert(const vectorf *in, const vectorf *devicex, const vectorf *devicey, const vectorf *devicez, vectorf *out); |
paul@0 | 37 | void vectorf_convert_into(const vectorf *in, const vectorf *x, const vectorf *y, const vectorf *z, vectorf *out); |
paul@0 | 38 | double vectorf_tilt_in_plane(const vectorf *in, const vectorf *x, const vectorf *y); |
paul@0 | 39 | double vectorf_tilt_in_plane_with_axis(const vectorf *in, const vectorf *x, const vectorf *y, const vectorf *z); |
paul@0 | 40 | void vectorf_rotate_in_space(const vectorf *in, const vectorf *x, const vectorf *y, const vectorf *z, double angle, vectorf *out); |
paul@0 | 41 | |
paul@0 | 42 | #define degrad(x) ((x) * M_PI / 180.0) |
paul@0 | 43 | #define raddeg(x) ((x) * 180.0 / M_PI) |
paul@0 | 44 | |
paul@0 | 45 | #define fdiv(x, y) (floor((int) ((x) / (y)))) |
paul@0 | 46 | |
paul@0 | 47 | /* Get the closest number at the given resolution. */ |
paul@0 | 48 | |
paul@0 | 49 | #define closest(x, res) (((int) (x) / (res)) * (res)) |
paul@0 | 50 | |
paul@0 | 51 | /* Get the maximum and minimum of the given numbers. */ |
paul@0 | 52 | |
paul@0 | 53 | #define max(x, y) ((x) >= (y) ? (x) : (y)) |
paul@0 | 54 | #define min(x, y) ((x) <= (y) ? (x) : (y)) |
paul@0 | 55 | |
paul@0 | 56 | /* Get the sign of a number. */ |
paul@0 | 57 | |
paul@0 | 58 | #define sign(x) ((x) == 0 ? 0 : (x) < 0 ? -1 : 1) |
paul@0 | 59 | |
paul@0 | 60 | /* Eliminate noise using the given threshold. */ |
paul@0 | 61 | |
paul@0 | 62 | #define noise(x, y) (fabs(x) < (y) ? 0 : (x)) |
paul@0 | 63 | |
paul@0 | 64 | #endif /* __GEO_H__ */ |