Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Line:
- def __init__(self, x1, y1, x2, y2):
- diffx = (x1-x2)
- diffy = (y1-y2)
- c = 0
- if diffx != 0:
- grad = diffy/diffx
- c = y1 - (x1*grad)
- else:
- c = x1
- self.c = c
- self.diffx = diffx
- self.diffy = diffy
- def getY(self, x):
- if self.diffx != 0:
- grad = self.diffy/self.diffx
- return (x*grad) + self.c
- else:
- return None
- def getX(self, y):
- if self.diffx != 0:
- grad = self.diffy/self.diffx
- return (y/grad) - (self.c/grad)
- else:
- return self.c
- def getNormal(self, x, y):
- if self.diffx != 0:
- if self.diffy != 0:
- grad = -1/(self.diffy/self.diffx)
- y2 = y - (grad*x) + (grad*(x+1))
- return Line(x, y, (x+1), y2)
- else:
- return Line(x, y, x, y + 1)
- else:
- return Line(x, y, x + 1, y)
- def getAngle(self):
- if self.diffx != 0 and self.diffy != 0:
- x1, y1 = self.getX(1), 1
- x2, y2 = self.getX(2), 2
- nx = x2 - x1
- ny = y2 - y1
- na = 0
- if nx > 0 and ny > 0:
- na = math.asin(nx/nforce)
- elif nx > 0 and ny < 0:
- na = pi - math.asin(math.fabs(nx)/nforce)
- elif nx < 0 and ny < 0:
- na = pi + math.asin(math.fabs(nx)/nforce)
- elif nx < 0 and ny > 0:
- na = (2*pi) - math.asin(math.fabs(nx)/nforce)
- else:
- raise Exception(" Impossible Coordinates: ", nx, ",", ny)
- return na, False
- elif self.diffx != 0:
- return (0), True
- elif self.diffy != 0:
- return (pi/2), True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement