summaryrefslogtreecommitdiff
path: root/vector.h
blob: 3838b63d72b677f7fd380ad7de3e532611112bb8 (plain)
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
#include <math.h>

typedef float scalar;

typedef struct vector_t {
    enum { RECT, SPH } type;
    union {
        struct {
            scalar x, y, z;
        } rect;
        struct {
            scalar r, elevation, azimuth;
        } sph;
    };
} vector;

scalar vect_abs(const vector*);

void vect_mul(vector*, scalar);
void vect_add(vector*, const vector*);

void vect_to_rect(vector*);
void vect_to_sph(vector*);
void vect_sub(vector*, const vector*);
void vect_negate(vector*);
void vect_normalize(vector*);

scalar vect_dot(const vector *v1, const vector *v2);