curvature
curvature copied to clipboard
Division by zero error on 1-1-2 triangles
For pairs of segments that have the same length and a base that is twice their length, the circumcircle-radius algorithm results in a division-by-zero error. The test script below will demonstrate this.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import math
import sys
a = 0.0949651002884
b = 0.0949651002884
c = 0.189930200577
a = 1
b = 1
c = 2
sys.stderr.write("\n\na={}\nb={}\nc={}\nfabs={}\n(a+b+c)={}\n(b+c-a)={}\n(c+a-b)={}\n(a+b-c)={}\n\n".format(a,b,c, math.fabs((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c)), (a+b+c), (b+c-a), (c+a-b), (a+b-c)))
r = (a * b * c)/math.sqrt(math.fabs((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c)))
print r
I've not yet found another algorithm for finding the circumcircle radius that doesn't have this issue, but there may be one out there.
I think the issue is that the three data points simply are in a straight line. If you imagine a triangle in which the base is equal to the two remaining sides the height will be very close to zero.
I think we can handle this by checking if the sum of a
and b
is less than c
we simply return the max radius
Oh, thanks for this explanation -- makes total sense. :-)