fixed seidel numerical accuracy bug

This commit is contained in:
zzzzrrr 2009-11-19 10:48:56 -05:00
parent 48805d55db
commit 7f473799ac
2 changed files with 7 additions and 5 deletions

View File

@ -11,7 +11,7 @@ class Poly2Tri(Game):
super(Poly2Tri, self).__init__(*self.screen_size)
# Load point set
file_name = "../data/dude.dat"
file_name = "../data/nazca_monkey.dat"
self.points = self.load_points(file_name)
# Triangulate
@ -30,7 +30,7 @@ class Poly2Tri(Game):
pass
def render(self):
reset_zoom(2.0, (400, 500), self.screen_size)
reset_zoom(8, (0, 0), self.screen_size)
red = 255, 0, 0
for t in self.triangles:
draw_polygon(t, red)

View File

@ -30,7 +30,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
from random import shuffle
from math import atan2, floor
from math import atan2
##
## Based on Raimund Seidel'e paper "A simple and fast incremental randomized
@ -94,10 +94,12 @@ class Edge(object):
self.mpoints.append(q)
def is_above(self, point):
return (floor(point.y) < floor(self.slope * point.x + self.b))
# NOTE rounding can effect numerical robustness
return (round(point.y, 10) < round(self.slope * point.x + self.b, 10))
def is_below(self, point):
return (floor(point.y) > floor(self.slope * point.x + self.b))
# NOTE rounding can effect numerical robustness
return (round(point.y, 10) > round(self.slope * point.x + self.b, 10))
def intersect(self, c, d):
a = self.p