1 /* vector.h: operations on vectors and points. */ 2 3 #ifndef VECTOR_H 4 #define VECTOR_H 5 6 #include "types.h" 7 #include "exception.h" 8 9 /* Our vectors are represented as displacements along the x and y axes. */ 10 11 typedef struct 12 { 13 at_real dx, dy, dz; 14 } vector_type; 15 16 17 /* Consider a point as a vector from the origin. */ 18 extern vector_type make_vector (const at_real_coord); 19 20 /* And a vector as a point, i.e., a displacement from the origin. */ 21 extern at_real_coord vector_to_point (const vector_type); 22 23 24 /* Definitions for these common operations can be found in any decent 25 linear algebra book, and most calculus books. */ 26 27 extern at_real magnitude (const vector_type); 28 extern vector_type normalize (const vector_type); 29 30 extern vector_type Vadd (const vector_type, const vector_type); 31 extern at_real Vdot (const vector_type, const vector_type); 32 extern vector_type Vmult_scalar (const vector_type, const at_real); 33 extern at_real Vangle (const vector_type in, const vector_type out, at_exception_type * exp); 34 35 /* These operations could have been named `P..._vector' just as well as 36 V..._point, so we may as well allow both names. */ 37 #define Padd_vector Vadd_point 38 extern at_real_coord Vadd_point 39 (const at_real_coord, const vector_type); 40 41 #define Psubtract_vector Vsubtract_point 42 extern at_real_coord Vsubtract_point 43 (const at_real_coord, const vector_type); 44 45 /* This returns the rounded sum. */ 46 #define IPadd_vector Vadd_int_point 47 extern at_coord Vadd_int_point 48 (const at_coord, const vector_type); 49 50 /* Take the absolute value of both components. */ 51 extern vector_type Vabs (const vector_type); 52 53 /* Operations on points with real coordinates. It is not orthogonal, 54 but more convenient, to have the subtraction operator return a 55 vector, and the addition operator return a point. */ 56 extern vector_type Psubtract 57 (const at_real_coord, const at_real_coord); 58 59 /* These are heavily used in spline fitting. */ 60 extern at_real_coord Padd (const at_real_coord, 61 const at_real_coord); 62 extern at_real_coord Pmult_scalar (const at_real_coord, const at_real); 63 64 /* Similarly, for points with integer coordinates; here, a subtraction 65 operator that does return another point is useful. */ 66 extern vector_type IPsubtract 67 (const at_coord, const at_coord); 68 extern at_coord IPsubtractP 69 (const at_coord, const at_coord); 70 extern at_coord IPadd 71 (const at_coord, const at_coord); 72 extern at_coord IPmult_scalar (const at_coord, const int); 73 extern at_real_coord IPmult_real 74 (const at_coord, const at_real); 75 extern at_bool IPequal (const at_coord, const at_coord); 76 77 #endif /* not VECTOR_H */ 78 79