add comments
This commit is contained in:
parent
9f71fa38a2
commit
98b3793446
@ -12,13 +12,13 @@ zero_vector = Vector(0,0)
|
||||
def main() -> None:
|
||||
print("Hello Teodora!")
|
||||
|
||||
displacement = displacementVector(current_pos, target_pos) # define function displacement
|
||||
displacement = displacementVector(current_pos, target_pos)
|
||||
print(displacement)
|
||||
|
||||
distance = length(displacement) ## define function distance
|
||||
distance = length(displacement)
|
||||
print(distance)
|
||||
|
||||
direction = safe_normalize(displacement, 0.001) # define function safe normalisation
|
||||
direction = safe_normalize(displacement, 2) # minimum distance = 0.001
|
||||
print(direction)
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ def displacementVector(current_pos, target_pos):
|
||||
return displacementVector
|
||||
|
||||
## distance between two positions
|
||||
# Euclidian norm
|
||||
# Euclidian norm measures vector length
|
||||
|
||||
def length(vector: Vector) -> float:
|
||||
squared_x = vector.x*vector.x
|
||||
@ -38,7 +38,7 @@ def length(vector: Vector) -> float:
|
||||
squared_x + squared_y
|
||||
return math.sqrt(squared_x + squared_y)
|
||||
|
||||
# safe normalisation
|
||||
## safe normalisation (keep the direction while ignoring the distance)
|
||||
# The minimum-distance check also prevents division by zero.
|
||||
|
||||
def safe_normalize(vector: Vector, minimum_distance: float) -> Vector:
|
||||
@ -47,6 +47,6 @@ def safe_normalize(vector: Vector, minimum_distance: float) -> Vector:
|
||||
if vector_length < minimum_distance:
|
||||
return zero_vector
|
||||
|
||||
einheitsVector = Vector(vector.x / vector_length, vector.y / vector_length)
|
||||
einheitsVector = Vector(vector.x / vector_length, vector.y / vector_length) # unit vector
|
||||
return einheitsVector
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user