Last active
April 6, 2022 11:14
-
-
Save pjpetersik/cbfb9b22cf504df2a310ea2afbe895fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function energy_usage(agent::Agent, model::Model) | |
usage = 0.02 | |
for other_agent in model.peloton | |
heading = other_agent.position - agent.position | |
distance = sum((heading).^2)^0.5 | |
if agent != other_agent | |
if distance < 0.2 && heading[1] > 0 | |
angle_factor = abs(acot(heading[2] / heading[1])) / π * 2 | |
usage -= 0.1 * (0.2 - distance) * angle_factor | |
end | |
end | |
end | |
return min(max(-0.01, usage), 0.02) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment