File: util.py

package info (click to toggle)
oneisenough 0.40-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 616 kB
  • sloc: python: 697; makefile: 7; sh: 2
file content (38 lines) | stat: -rw-r--r-- 849 bytes parent folder | download | duplicates (5)
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
def normalize(value):
  abvalue = 0
  for v in value:
    abvalue = abvalue + v**2
  abvalue = abvalue**(0.5)
  if abvalue:
    for v in value:
      v = v / abvalue
  return value

def crossed(value1, value2, border):
  if (value1 <= border and value2 > border) or (value1 >= border and value2 < border):
    return True
  else:
    return False

def absvector(value):
  abvalue = 0
  for v in value:
    abvalue = abvalue + v**2
  abvalue = abvalue**(0.5)
  return abvalue

class Sphere:

  def __init__(self, x, y, radius):
    self.x = x
    self.y = y
    self.radius = radius
    return

  def collidesphere(self, sphere2):
    dist = absvector((self.x - sphere2.x, self.y - sphere2.y))
    radiuses = (self.radius + sphere2.radius)
    if  dist < radiuses:
      return True
    else:
      return False