Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yangliu28
GitHub Repository: yangliu28/swarm_formation_sim
Path: blob/master/formation_functions.py
104 views
1
# common functions for the formation simulations
2
3
import math
4
import time
5
6
# reset radian angle to [-pi, pi)
7
def reset_radian(radian):
8
while radian >= math.pi:
9
radian = radian - 2*math.pi
10
while radian < -math.pi:
11
radian = radian + 2*math.pi
12
return radian
13
14
# convert positions in physics coordinates to display coordinates
15
def world_to_display(input_pos, world_size, display_size):
16
pos_display = [0, 0]
17
pos_display[0] = int(input_pos[0]/world_size[0] * display_size[0])
18
pos_display[1] = int((1-input_pos[1]/world_size[1]) * display_size[1])
19
return pos_display
20
21
# return date and time in a string, connected with dash, for filename
22
def get_date_time():
23
return (time.strftime('%Y') + '-' +
24
time.strftime('%m') + '-' +
25
time.strftime('%d') + '-' +
26
time.strftime('%H') + '-' +
27
time.strftime('%M') + '-' +
28
time.strftime('%S'))
29
30
31
32