Skip to content
Snippets Groups Projects
Commit a3a670b6 authored by Davis, Duane T's avatar Davis, Duane T
Browse files

Circle calculation bug fix

parent 6bbdb5de
No related branches found
No related tags found
No related merge requests found
......@@ -335,9 +335,9 @@ def determinant3x3(m):
@param m: 3x3 matrix ( (a11, a12, a13), (a21, a22, a23), (a31, a32, a33))
@return determinant of the matrix m
'''
return m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - \
m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + \
m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0])
return m[0][0] * determinant((m[1][1], m[1][2]), (m[2][1], m[2][2])) - \
m[0][1] * determinant((m[1][0], m[1][2]), (m[2][0], m[2][2])) + \
m[0][2] * determinant((m[1][0], m[1][1]), (m[2][0], m[2][1]))
def dot_product(pt1, pt2):
......@@ -561,21 +561,20 @@ def compute_circle(pt1, pt2, pt3):
x3y3Sqr = pt3[0] * pt3[0] + pt3[1] * pt3[1]
try:
centerX = determinant3x3(((x1y1Sqr, pt1[1], 1.0), \
(x2y2Sqr, pt2[1], 1.0), \
(x3y3Sqr, pt3[1], 1.0))) / \
(2.0 * determinant3x3(((pt1[0], pt1[1], 1.0), \
(pt2[1], pt2[1], 1.0), \
(pt3[1], pt3[1], 1.0))))
centerY = determinant3x3(((pt1[0], x1y1Sqr, 1.0), \
(pt2[0], x2y2Sqr, 1.0), \
(pt3[0], x3y3Sqr, 1.0))) / \
(2.0 * determinant3x3(((pt1[0], pt1[1], 1.0), \
(pt2[0], pt2[1], 1.0), \
(pt3[0], pt3[1], 1.0))))
detA = determinant3x3(((pt1[0], pt1[1], 1.0), \
(pt2[0], pt2[1], 1.0), \
(pt3[0], pt3[1], 1.0)))
detB = -determinant3x3(((x1y1Sqr, pt1[1], 1.0), \
(x2y2Sqr, pt2[1], 1.0), \
(x3y3Sqr, pt3[1], 1.0)))
detC = determinant3x3(((x1y1Sqr, pt1[0], 1.0), \
(x2y2Sqr, pt2[0], 1.0), \
(x3y3Sqr, pt3[0], 1.0)))
centerX = -detB/(2.0*detA)
centerY = -detC/(2.0*detA)
radius = cartesian_distance((centerX, centerY), pt1)
return ( ( centerX, centerY ), radius )
except: # probably division by zero--means the points are colinear
except Exception as ex: # probably division by zero--means the points are colinear
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment