forked from smcameron/space-nerds-in-space
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathutils.h
76 lines (60 loc) · 3.12 KB
/
mathutils.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
#ifndef __MATHUTILS_H__
#define __MATHUTILS_H__
/*
Copyright (C) 2010 Stephen M. Cameron
Author: Stephen M. Cameron
This file is part of Spacenerds In Space.
Spacenerds in Space 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 2 of the License, or
(at your option) any later version.
Spacenerds in Space 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 Spacenerds in Space; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define PI (3.14159265)
#ifndef DEFINE_MATHUTILS_GLOBALS
#define GLOBAL extern
#else
#define GLOBAL
#endif
GLOBAL double degrees_to_radians(double degrees);
GLOBAL double radians_to_degrees(double radians);
#define SNIS_RAND_MAX (32767)
GLOBAL int snis_rand(void); /* like rand() */
GLOBAL void snis_srand(unsigned seed); /* like srand() */
GLOBAL int snis_randn(int n); /* returns n * snis_rand() / SNIS_RAND_MAX */
GLOBAL float snis_random_float(); /* return random number -1 <= n <= 1 */
GLOBAL void normalize_angle(double *angle);
GLOBAL double interpolate(double x, double x1, double y1, double x2, double y2);
GLOBAL double table_interp(double x, double xv[], double yv[], int nv);
GLOBAL double game_angle_to_math_angle(double angle);
GLOBAL double math_angle_to_game_angle(double angle);
/* given two points, (x1,y1) and (x2, y2) find eqn of line Ax + By = C */
GLOBAL void line_eqn_from_two_points(double x1, double y1, double x2, double y2,
double *A, double *B, double *C);
/* Given two line eqns, A1x + B1y = C1 and A2x + B2y = C2, find the intersection
* point. If lines are parallel and thus do not intersect, return -1, otherwise
* return 0 */
GLOBAL int line_intersection(double A1, double B1, double C1,
double A2, double B2, double C2, double *x, double *y);
/* Given 2 points (x1,y1), (x2,y2), find equation of the line which is perpendicular
* to the line passing through the two points, and which intersects the midpoint
* between the two points. */
GLOBAL void perpendicular_line_from_two_points(double x1, double y1, double x2, double y2,
double *A, double *B, double *C);
/* Given three points on the edge of a circle, find the circle x, y, r. If no solution,
returns -1, otherwise 0 */
GLOBAL int circle_from_three_points(double x1, double y1, double x2, double y2, double x3, double y3,
double *x, double *y, double *r);
/* Return random point on surface of sphere of given radius */
GLOBAL void random_point_on_sphere(float radius, float *x, float *y, float *z)
;
/* return random point inside sphere of specified radius */
GLOBAL void random_point_in_sphere(float radius, float *x, float *y, float *z,
float *dist3dsqrd);
#endif