Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Division by zero error on 1-1-2 triangles #40

Open
adamfranco opened this issue May 20, 2016 · 2 comments
Open

Division by zero error on 1-1-2 triangles #40

adamfranco opened this issue May 20, 2016 · 2 comments
Labels

Comments

@adamfranco
Copy link
Owner

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.

@adamfranco adamfranco added the bug label May 20, 2016
@Fonsan
Copy link
Contributor

Fonsan commented Jan 14, 2017

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

@adamfranco
Copy link
Owner Author

Oh, thanks for this explanation -- makes total sense. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants