-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovement.py
44 lines (37 loc) · 1.2 KB
/
movement.py
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
## movement.py Version 1.0
## Written by Magnus Berg Sletfjerding (eembees)
###########################################################
"""
Movement function:
Moves a set of points along a randomly generated direction vector
INPUTS:
points -- Points as ndarray
dist -- Distance points move
OUTPUTS:
newpoints -- New Points as ndarray
"""
"""
Importing modules
"""
import numpy as np
"""
Defining move function
"""
def randommove(points, dist):
# # Standard factors
dimension = len(points[0]) # # working dimension of coordinate system, extracted from first point
# # Generate random direction vector
direction = np.random.random_sample(dimension)
direction = [(x-0.5)*2 for x in direction]
# print direction
sqrtsum_random = np.sqrt(sum([x**2 for x in direction]))
direction = [direction[i] / sqrtsum_random for i in range(dimension)]
# # Obtain movement vector
movement = [direction[i]*dist for i in range(dimension)]
# # Initiate movement
newpoints = [] # # List of output points
# print type(newpoints)
for i in range(len(points)):
newpoint = np.add(points[i], movement)
newpoints.append(newpoint)
return np.asarray(newpoints)