-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.h
71 lines (62 loc) · 1.39 KB
/
vector.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
/**
* @file
*
* @author Christopher Blöcker
*/
#ifndef __VECTOR_H__
#define __VECTOR_H__
/* -------------------------------------------------------------------------- */
typedef struct {
double x
, y
;
} Vector;
/* -------------------------------------------------------------------------- */
#define vectorLength(u) (sqrt((u.x)*(u.x)+(u.y)*(u.y)))
/* -------------------------------------------------------------------------- */
/**
* Creates a 2D vector.
*
* @param[in] x x-component.
* @param[in] y y-component.
*
* @return The vector with the given components.
*/
extern Vector vectorMake(double x, double y);
/**
* Adds two vectors.
*
* @param[in] u First vector.
* @param[in] v Second vector.
*
* @return u+v.
*/
extern Vector vectorAdd(Vector u, Vector v);
/**
* Subtracts one vector from another.
*
* @param[in] u First vector.
* @param[in] v Second vector.
*
* @return u-v.
*/
extern Vector vectorSub(Vector u, Vector v);
/**
* Scales a vector by a scalar.
*
* @param[in] u Vector that should be scaled.
* @param[in] s Scaling factor.
*
* @return v*s.
*/
extern Vector vectorScale(Vector u, double s);
/**
* Rotates a vector by the given angle.
*
* @param[in] u Vector that should be rotated.
* @param[in] angle Rotation angle.
*
* @return Vector rotated by the given angle.
*/
extern Vector vectorRotate(Vector u, double angle);
#endif