You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: courses/artificialintelligence/assignments/flocking/README.md
+33-32Lines changed: 33 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,10 @@ Flocking is a behavior that is observed in birds, fish and other animals that mo
10
10
11
11
- \( \vec{F} \) means a vector \( F \) that has components. In a 2 dimensional vector it will hold \( F_x \) and \( F_y \). For example, if \( F_x = 1 \) and \( F_y = 3 \), then \( \vec{F} = (1,3) \)
12
12
- Simple math operations between vectors are done component-wise. For example, if \( \vec{F} = (1,1) \) and \( \vec{G} = (2,2) \), then \( \vec{F} + \vec{G} = (3,3) \)
13
-
- The notation \( \vec{P_{1}P_{2}} \) means the vector that goes from \( P_1 \) to \( P_2 \). It is the same as \( P_2-P_1 \)
13
+
- The notation \( \overrightarrow{P_{1}P_{2}} \) means the vector that goes from \( P_1 \) to \( P_2 \). It is the same as \( P_2-P_1 \)
14
14
- The modulus notation means the length (magnitude) of the vector. \( |\vec{F}| = \sqrt{F_x^2+F_y^2} \) For example, if \( \vec{F} = (1,1) \), then \( |\vec{F}| = \sqrt{2} \)
15
15
- The hat ^ notation means the normalized vector(magnitude is 1) of the vector. \( \hat{F} = \frac{\vec{F}}{|\vec{F}|} \) For example, if \( \vec{F} = (1,1) \), then \( \hat{F} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}}) \)
16
-
- The hat notation over 2 points means the normalized vector that goes from the first point to the second point. \( \hat{P_1P_2} = \frac{\vec{P_1P_2}}{|\vec{P_1P_2}|} \) For example, if \( P_1 = (0,0) \) and \( P_2 = (1,1) \), then \( \widehat{P_1P_2} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}}) \)
16
+
- The hat notation over 2 points means the normalized vector that goes from the first point to the second point. \( \widehat{P_1P_2} = \frac{\overrightarrow{P_1P_2}}{|\overrightarrow{P_1P_2}|} \) For example, if \( P_1 = (0,0) \) and \( P_2 = (1,1) \), then \( \widehat{P_1P_2} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}}) \)
17
17
- The sum \( \sum \) notation means the sum of all elements in the list going from `0` to `n-1`. Ex. \( \sum_{i=0}^{n-1} \vec{V_i} = \vec{V_0} + \vec{V_1} + \vec{V_2} + ... + \vec{V_{n-1}} \)
18
18
19
19
It is your job to implement those 3 behaviors following the ruleset below:
@@ -22,9 +22,9 @@ It is your job to implement those 3 behaviors following the ruleset below:
22
22
23
23
Apply a force towards the center of mass of the group.
24
24
25
-
1. The \( n \) neighbors of an agent are all the other agents that are within a certain radius of the agent. It doesnt include the agent itself;
25
+
1. The \( n \) neighbors of an agent are all the other agents that are within a certain radius \( r_c \)( `<` operation ) of the agent. It doesn't include the agent itself;
26
26
2. Compute the location of the center of mass of the group (\( P_{CM} \));
27
-
3. Compute the force that will move the agent towards the center of mass(\( \vec{F_{c}} \)); The farther the agent is from the center of mass, the force increases linearly up to the limit of the cohesion radius \( r_c \).
27
+
3. Compute the force that will move the agent towards the center of mass(\( \overrightarrow{F_c} \)); The farther the agent is from the center of mass, the force increases linearly up to the limit of the cohesion radius \( r_c \).
Note that the maximum magnitude of \( F_c \) is 1. Inclusive. This value can be multiplied by a constant \( K_c \) to increase or decrease the cohesion force to looks more appealing.
44
+
Note that the maximum magnitude of \( \overrightarrow{F_c} \) is 1. Inclusive. This value can be multiplied by a constant \( K_c \) to increase or decrease the cohesion force to looks more appealing.
45
45
46
46
??? example "Cohesion Example"
47
47
@@ -51,16 +51,16 @@ F_c = \begin{cases}
51
51
52
52
It will move the agent away from other agents when they get too close.
53
53
54
-
1. The \( n \) neighbors of an agent are all the other agents that are within the separation radius of the agent;
54
+
1. The \( n \) neighbors of an agent are all the other agents that are within the separation radius \( r_s \)of the agent;
55
55
2. If the distance to a neighbor is less than the separation radius, then the agent will move away from it inversely proportionally to the distance between them.
56
-
3. Accumulate the forces that will move the agent away from each neighbor (\( \vec{F_{s}} \)). And then, clamp the force to a maximum value of \( F_{Smax} \).
56
+
3. Accumulate the forces that will move the agent away from each neighbor (\( \overrightarrow{F_{s}} \)). And then, clamp the force to a maximum value of \( F_{Smax} \).
@@ -71,9 +71,9 @@ It will move the agent away from other agents when they get too close.
71
71
The force will go near infinite when the distance between the agent and the \( n \) neighbor is 0. To avoid this, after accumulating all the influences from every neighbor, the force will be clamped to a maximum magnitude of \( F_{Smax} \).
@@ -108,28 +108,28 @@ It is the force that will align the velocity of the agent with the average veloc
108
108
109
109
The force composition is made by a weighted sum of the influences of those 3 behaviors. This is the way we are going to work, this is not the only way to do it, nor the more correct. It is just a way to do it.
110
110
111
-
-\( \vec{F} = K_c \cdot \vec{F_c} + K_s \cdot \vec{F_s} + K_a \cdot \vec{F_a} \)`This is a weighted sum!`
112
-
-\( \vec{V_{new}} = \vec{V_{cur}} + \vec{F} \cdot \Delta t \)`This is a simplification!`
113
-
-\( P_{new} = P_{cur}+\vec{V_{new}} \cdot \Delta t \)`This is an approximation!`
111
+
-\( \vec{F} = K_c \cdot \overrightarrow{F_c} + K_s \cdot \overrightarrow{F_s} + K_a \cdot \overrightarrow{F_a} \)`This is a weighted sum!`
112
+
-\( \overrightarrow{V_{new}} = \overrightarrow{V_{cur}} + \vec{F} \cdot \Delta t \)`This is a simplification!`
113
+
-\( P_{new} = P_{cur}+\overrightarrow{V_{new}} \cdot \Delta t \)`This is an approximation!`
114
114
115
115
!!! warning
116
116
117
117
A more precise way for representing the new position would be to use full equations of motion. But given timestep is usually very small and it even squared, it is acceptable to ignore it. But here they are anyway, just dont use them in this assignment:
118
118
119
-
- \( \vec{V_{new}} = \vec{V_{cur}}+\frac{\vec{F}}{m} \cdot \Delta t \)
-\( \overrightarrow{F} \) is the force applied to the agent;
125
+
-\( \overrightarrow{V} \) is the velocity of the agent;
126
126
-\( P \) is the position of the agent;
127
127
-\( m \) is the mass of the agent, here it is always 1;
128
128
-\( \Delta t \) is the time frame (1/FPS);
129
129
-\( cur \) is the current value of the variable;
130
130
-\( new \) is the new value of the variable to be used in the next frame.
131
131
132
-
The \( \vec{V_{new}} \) and \( P_{new} \) are the ones that will be used in the next frame and you will have to print to the console at the end of every single frame.
132
+
The \( \overrightarrow{V_{new}} \) and \( P_{new} \) are the ones that will be used in the next frame and you will have to print to the console at the end of every single frame.
133
133
134
134
!!! note
135
135
@@ -202,7 +202,8 @@ The expected output is the position and velocity for each agent after the simula
0 commit comments