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
#ifndef __FORCES_H__
#define __FORCES_H__
#include "scene.h"
/**
* Calling this function will add a specialized force applier to a scene.
* The force applier will apply gravity between two bodies in each tick.
*
* The force applier will compute the Newtonian gravitational force between the
* bodies.
* See https://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation#Vector_form.
* The force should not be applied when the bodies are very close,
* because its magnitude blows up as the distance between the bodies goes to 0.
*
* @param scene the scene containing the bodies
* @param G the gravitational proportionality constant
* @param body1 the first body
* @param body2 the second body
*/
void create_newtonian_gravity(scene_t *scene, double G, body_t *body1, body_t *body2);
/**
* Calling this function will add a specialized force applier to a scene.
* The force applier will apply the spring force between two bodies in each tick.
*
* The force applier will compute the Hooke's-Law spring force between the
* bodies.
* See https://en.wikipedia.org/wiki/Hooke%27s_law.
*
* @param scene the scene containing the bodies
* @param k the Hooke's constant for the spring
* @param body1 the first body
* @param body2 the second body
*/
void create_spring(scene_t *scene, double k, body_t *body1, body_t *body2);
/**
* Calling this function will add a specialized force applier to a scene.
* The force applier will apply a drag force to a body in each tick.
*
* The force applier will compute the drag force on the body proportional to
* its velocity.
* The force points opposite the body's velocity.
*
* @param scene the scene containing the bodies
* @param gamma the proportionality constant between force and velocity
* (higher gamma means more drag)
* @param body the body to slow down
*/
void create_drag(scene_t *scene, double gamma, body_t *body);
#endif // #ifndef __FORCES_H__