Commit a9a0c569 authored by sumpfralle's avatar sumpfralle

prevent division by zero for non-ODE PushCutter operations


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@219 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 7f321114
...@@ -2,39 +2,51 @@ import math ...@@ -2,39 +2,51 @@ import math
class Point: class Point:
id=0 id=0
def __init__(self,x,y,z): def __init__(self,x,y,z):
self.id = Point.id self.id = Point.id
Point.id += 1 Point.id += 1
self.x = float(x) self.x = float(x)
self.y = float(y) self.y = float(y)
self.z = float(z) self.z = float(z)
def __repr__(self): def __repr__(self):
return "Point%d<%g,%g,%g>" % (self.id,self.x,self.y,self.z) return "Point%d<%g,%g,%g>" % (self.id,self.x,self.y,self.z)
def mul(self, c): def mul(self, c):
return Point(self.x*c,self.y*c,self.z*c) return Point(self.x*c,self.y*c,self.z*c)
def div(self, c): def div(self, c):
return Point(self.x/c,self.y/c,self.z/c) return Point(self.x/c,self.y/c,self.z/c)
def add(p1, p2): def add(p1, p2):
return Point(p1.x+p2.x,p1.y+p2.y,p1.z+p2.z) return Point(p1.x+p2.x,p1.y+p2.y,p1.z+p2.z)
def sub(p1, p2): def sub(p1, p2):
return Point(p1.x-p2.x,p1.y-p2.y,p1.z-p2.z) return Point(p1.x-p2.x,p1.y-p2.y,p1.z-p2.z)
def dot(p1, p2): def dot(p1, p2):
return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z
def cross(p1, p2): def cross(p1, p2):
return Point(p1.y*p2.z-p2.y*p1.z, p2.x*p1.z-p1.x*p2.z, p1.x*p2.y-p2.x*p1.y) return Point(p1.y*p2.z-p2.y*p1.z, p2.x*p1.z-p1.x*p2.z, p1.x*p2.y-p2.x*p1.y)
def normsq(self): def normsq(self):
if not hasattr(self, "_normsq"): if not hasattr(self, "_normsq"):
self._normsq = self.dot(self) self._normsq = self.dot(self)
return self._normsq return self._normsq
def norm(self): def norm(self):
if not hasattr(self, "_norm"): if not hasattr(self, "_norm"):
self._norm = math.sqrt(self.normsq()) self._norm = math.sqrt(self.normsq())
return self._norm return self._norm
def normalize(self): def normalize(self):
n = self.norm() n = self.norm()
self.x /= n if n != 0:
self.y /= n self.x /= n
self.z /= n self.y /= n
self.z /= n
self._norm = 1.0 self._norm = 1.0
self._normsq = 1.0 self._normsq = 1.0
return self return self
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment