Commit 514225d5 authored by lode_leroy's avatar lode_leroy

fix circumcircle

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@76 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent bde8fc53
......@@ -125,9 +125,9 @@ class Triangle:
def normal(self):
if self._normal is None:
# calculate normal, if p1-p2-pe are in clockwise order
self._normal = self.p3.sub(self.p1).cross(self.p2.sub(self.p1))
denom = self._normal.norm()
self._normal = self._normal.div(denom)
n = self.p3.sub(self.p1).cross(self.p2.sub(self.p1))
n.normalize()
self._normal = n
return self._normal
def plane(self):
......@@ -211,12 +211,19 @@ class Triangle:
return self._radiussq
def calc_circumcircle(self):
normal = self.normal()
self._radius = (self.p2.sub(self.p1).norm()*self.p3.sub(self.p2).norm()*self.p3.sub(self.p1).norm())/(2)
# we can't use the cached value of "normal", since we don't want the normalized value
normal = self.p2.sub(self.p1).cross(self.p3.sub(self.p2))
print "normal=",normal
denom = normal.norm()
print "denom=",denom
self._radius = (self.p2.sub(self.p1).norm()*self.p3.sub(self.p2).norm()*self.p3.sub(self.p1).norm())/(2*denom)
print "radius=",self._radius
self._radiussq = self._radius*self._radius
alpha = self.p3.sub(self.p2).normsq()*(self.p1.sub(self.p2).dot(self.p1.sub(self.p3))) / 2
beta = self.p1.sub(self.p3).normsq()*(self.p2.sub(self.p1).dot(self.p2.sub(self.p3))) / 2
gamma = self.p1.sub(self.p2).normsq()*(self.p3.sub(self.p1).dot(self.p3.sub(self.p2))) / 2
denom2 = 2*denom*denom
alpha = self.p3.sub(self.p2).normsq()*(self.p1.sub(self.p2).dot(self.p1.sub(self.p3))) / (denom2)
beta = self.p1.sub(self.p3).normsq()*(self.p2.sub(self.p1).dot(self.p2.sub(self.p3))) / (denom2)
gamma = self.p1.sub(self.p2).normsq()*(self.p3.sub(self.p1).dot(self.p3.sub(self.p2))) / (denom2)
print "alpha=",alpha,", beta=",beta,", gamma=",gamma
self._middle = Point(self.p1.x*alpha+self.p2.x*beta+self.p3.x*gamma,
self.p1.y*alpha+self.p2.y*beta+self.p3.y*gamma,
self.p1.z*alpha+self.p2.z*beta+self.p3.z*gamma)
......
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