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

View File

@ -30,7 +30,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# #
from random import shuffle 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 ## Based on Raimund Seidel'e paper "A simple and fast incremental randomized
@ -94,10 +94,12 @@ class Edge(object):
self.mpoints.append(q) self.mpoints.append(q)
def is_above(self, point): 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): 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): def intersect(self, c, d):
a = self.p a = self.p