#ifndef r3_H #define r3_H /* Operations on points and vectors of R^3 */ /* Last edited on 2005-01-16 15:01:18 by stolfi */ /* Copyright © 2005 Jorge Stolfi, UNICAMP. See note at end of file. */ #include typedef struct { double c[3]; } r3_t; void r3_zero (r3_t *r); /* Sets {r} to the zero vector. */ void r3_all (double x, r3_t *r); /* Sets all coordinates of {r} to the value {x}. */ void r3_axis (int i, r3_t *r); /* Sets {r} to the {i}th vector of the canonical basis. */ void r3_add (r3_t *a, r3_t *b, r3_t *r); /* Sets {r = a + b}. */ void r3_sub (r3_t *a, r3_t *b, r3_t *r); /* Sets {r = a - b}. */ void r3_neg (r3_t *a, r3_t *r); /* Sets {r} to {-a}. */ void r3_scale (double s, r3_t *a, r3_t *r); /* Sets {r := s * a}. */ void r3_mix (double s, r3_t *a, double t, r3_t *b, r3_t *r); /* Sets {r := s * a + t * b}. */ void r3_mix_in (double s, r3_t *a, r3_t *r); /* Sets {r := r + s * a}. */ void r3_weigh (r3_t *a, r3_t *w, r3_t *r); /* Sets {r[i] := a[i] * w[i]}. */ double r3_norm (r3_t *a); /* Returns the Euclidean length of {a}. */ double r3_norm_sqr (r3_t *a); /* Returns the square of the Euclidean length of {a}. */ double r3_L_inf_norm (r3_t *a); /* Returns the L-infinity norm of {a} (max absolute coordinate). */ double r3_dist (r3_t *a, r3_t *b); /* Returns the Euclidean distance between {a} and {b}. */ double r3_dist_sqr (r3_t *a, r3_t *b); /* Returns the square of the Euclidean distance between {a} and {b}. */ double r3_L_inf_dist (r3_t *a, r3_t *b); /* Returns the L-infinity distance between {a} and {b} (max absolute diff). */ double r3_dir (r3_t *a, r3_t *r); /* Sets {r} to {a} normalized to unit Euclidean length; returns the original length. */ double r3_L_inf_dir (r3_t *a, r3_t *r); /* Sets {r} to the vector {a/r3_L_inf_norm(a)}; returns the original norm. */ double r3_dot (r3_t *a, r3_t *b); /* Dot product of vectors {a} and {b}. */ double r3_cos (r3_t *a, r3_t *b); /* Cosine of angle between vectors {a} and {b}. */ double r3_sin (r3_t *a, r3_t *b); /* Absolute sine of angle between vectors {a} and {b}. */ void r3_cross (r3_t *a, r3_t *b, r3_t *r); /* Sets {r} to the cross product of {a} and {b}. */ double r3_det (r3_t *a, r3_t *b, r3_t *c); /* Returns the determinant of the 3 x 3 matrix whose rows are {a,b,c}. */ double r3_decomp (r3_t *a, r3_t *u, r3_t *para, r3_t *perp); /* Sets {para} and {perp} (when not NULL) to the components of {a} that are parallel and perpendicular to to {u}, respectively. Namely, {para = c*u} and {perp = a - c*u}, where {c = r3_dot(a,u)/r3_dot(u,u)}. Also returns {c}. */ void r3_throw_cube (r3_t *r); /* Sets {r} to a uniformly random point of the 3-cube {[-1 .. +1]^3}. */ void r3_throw_ball (r3_t *r); /* Sets {r} to a uniformly random point of the unit N-ball. */ void r3_throw_normal (r3_t *r); /* Sets each coordinate {r[i]} to an independent Gaussian random number with zero mean and unit standard deviation. */ void r3_print (FILE *f, r3_t *a); /* Prints {a} on file {f}, with some default format. */ void r3_gen_print (FILE *f, r3_t *a, char *fmt, char *lp, char *sep, char *rp); /* Prints {a} on file {f}, formatting each coordinate with {fmt}. The strings {lp}, {sep}, and {rp} are printed respectively before, between, and after all the coordinates of {a}. When NULL, they default to "%16.8e", "(", " ", and ")", respectively. */ #endif /* COPYRIGHT AND AUTHORSHIP NOTICE Copyright © 2005 Jorge Stolfi, Universidade Estadual de Campinas (UNICAMP). Created by Jorge Stolfi in 1992--2005. This source file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved in all copies, and that any modified versions of this file are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the author nor his employers shall be held responsible for any losses or damages that may result from its use. END OF NOTICE */