misc bugfixes

This commit is contained in:
Johann Dreo 2014-05-26 11:36:16 +02:00
commit 126692747d
4 changed files with 22 additions and 16 deletions

View file

@ -148,7 +148,7 @@ triangulated = []
if args.triangulation: if args.triangulation:
with open(args.triangulation) as fd: with open(args.triangulation) as fd:
triangulated = triangulation.load(args.triangulation) triangulated = triangulation.load(fd)
else: else:
LOGN( "Compute the triangulation of the penrose vertices" ) LOGN( "Compute the triangulation of the penrose vertices" )
@ -157,13 +157,8 @@ else:
LOGN( "\tRemove triangles that are not sub-parts of the Penrose tiling" ) LOGN( "\tRemove triangles that are not sub-parts of the Penrose tiling" )
def acute_triangle(triangle):
"""Return True if the center of the circumcircle of the given triangle lies inside the triangle.
That is if the triangle is acute."""
return triangulation.in_triangle( triangulation.circumcircle(triangle)[0], triangle )
# Filter out triangles that are obtuse # Filter out triangles that are obtuse
triangulated = list(filter_if_not( acute_triangle, triangles )) triangulated = list(filter_if_not( triangulation.is_acute, triangles ))
LOGN( "\t\tRemoved", len(triangles)-len(triangulated), "triangles" ) LOGN( "\t\tRemoved", len(triangles)-len(triangulated), "triangles" )
with open("d%i_triangulation.triangles" % depth, "w") as fd: with open("d%i_triangulation.triangles" % depth, "w") as fd:

View file

@ -104,15 +104,23 @@ def in_triangle( p0, triangle, exclude_edges = False ):
beta = ( (y(p3) - y(p1)) * (x(p0) - x(p3)) + (x(p1) - x(p3)) * (y(p0) - y(p3)) ) \ beta = ( (y(p3) - y(p1)) * (x(p0) - x(p3)) + (x(p1) - x(p3)) * (y(p0) - y(p3)) ) \
/ ( (y(p2) - y(p3)) * (x(p1) - x(p3)) + (x(p3) - x(p2)) * (y(p1) - y(p3)) ) / ( (y(p2) - y(p3)) * (x(p1) - x(p3)) + (x(p3) - x(p2)) * (y(p1) - y(p3)) )
gamma = 1.0 - alpha - beta gamma = 1.0 - alpha - beta
# print alpha,beta,gamma
if exclude_edges: if exclude_edges:
# If all of alpha, beta, and gamma are strictly greater than 0 and lower than 1, # If all of alpha, beta, and gamma are strictly greater than 0 and lower than 1,
# (and thus if any of them are lower or equal than 0 or greater than 1) # (and thus if any of them are lower or equal than 0 or greater than 1)
# then the point p0 strictly lies within the triangle. # then the point p0 strictly lies within the triangle.
return any( x <= 0 or 1 <= x for x in (alpha, beta, gamma ) ) return any( x <= 0 or 1 <= x for x in (alpha, beta, gamma) )
else: else:
# If the inequality is strict, then the point may lies on an edge. # If the inequality is strict, then the point may lies on an edge.
return any( x < 0 or 1 < x for x in (alpha, beta, gamma ) ) return any( x < 0 or 1 < x for x in (alpha, beta, gamma) )
def is_acute(triangle):
"""Return True if the center of the circumcircle of the given triangle lies inside the triangle.
That is if the triangle is acute."""
return in_triangle( circumcircle(triangle)[0], triangle )
def bounds( vertices ): def bounds( vertices ):
@ -349,12 +357,12 @@ def load( stream ):
triangles = [] triangles = []
for line in stream: for line in stream:
if line.strip()[0] != "#": if line.strip()[0] != "#":
tri = line.split() tri = line.strip().split()
assert(len(tri)==3) assert(len(tri)==3)
triangle = [] triangle = []
for p in tri: for p in tri:
assert(len(p)==2) point = tuple(float(i) for i in p.split(","))
point = [ (float(y),float(y)) for i,j in p.split(",")] assert(len(point)==2)
triangle.append( point ) triangle.append( point )
triangles.append( triangle ) triangles.append( triangle )
return triangles return triangles

View file

@ -21,7 +21,7 @@ def load_points( stream ):
points = [] points = []
for line in stream: for line in stream:
if line.strip()[0] != "#": if line.strip()[0] != "#":
p = tuple([float(i) for i in line.split()]) p = tuple([float(i) for i in line.split(",")])
assert(len(p)==2) assert(len(p)==2)
points.append( p ) points.append( p )
return points return points
@ -36,12 +36,12 @@ def load_segments( stream ):
segments = [] segments = []
for line in stream: for line in stream:
if line.strip()[0] != "#": if line.strip()[0] != "#":
seg = line.strip() seg = line.strip().split()
assert(len(seg)==2) assert(len(seg)==2)
edge = [] edge = []
for p in seg: for p in seg:
assert(len(p)==2) point = tuple([float(i) for i in p.split(",")])
point = tuple([float(i) for i in seg]) assert(len(point)==2)
edge.append( point ) edge.append( point )
segments.append( edge ) segments.append( edge )
return segments return segments

View file

@ -56,6 +56,9 @@ def dual( triangles ):
for triangle in triangles: for triangle in triangles:
assert( len(triangle) == 3 ) assert( len(triangle) == 3 )
# if not triangulation.is_acute(triangle):
# print triangle
assert( triangulation.is_acute(triangle) )
current_node = triangulation.circumcircle(triangle)[0] current_node = triangulation.circumcircle(triangle)[0]
assert( len(current_node) == 2 ) assert( len(current_node) == 2 )