misc bugfixes
This commit is contained in:
parent
c35c8d1186
commit
126692747d
4 changed files with 22 additions and 16 deletions
|
|
@ -148,7 +148,7 @@ triangulated = []
|
|||
|
||||
if args.triangulation:
|
||||
with open(args.triangulation) as fd:
|
||||
triangulated = triangulation.load(args.triangulation)
|
||||
triangulated = triangulation.load(fd)
|
||||
|
||||
else:
|
||||
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" )
|
||||
|
||||
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
|
||||
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" )
|
||||
|
||||
with open("d%i_triangulation.triangles" % depth, "w") as fd:
|
||||
|
|
|
|||
|
|
@ -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)) ) \
|
||||
/ ( (y(p2) - y(p3)) * (x(p1) - x(p3)) + (x(p3) - x(p2)) * (y(p1) - y(p3)) )
|
||||
gamma = 1.0 - alpha - beta
|
||||
# print alpha,beta,gamma
|
||||
|
||||
if exclude_edges:
|
||||
# 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)
|
||||
# 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:
|
||||
# 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 ):
|
||||
|
|
@ -349,12 +357,12 @@ def load( stream ):
|
|||
triangles = []
|
||||
for line in stream:
|
||||
if line.strip()[0] != "#":
|
||||
tri = line.split()
|
||||
tri = line.strip().split()
|
||||
assert(len(tri)==3)
|
||||
triangle = []
|
||||
for p in tri:
|
||||
assert(len(p)==2)
|
||||
point = [ (float(y),float(y)) for i,j in p.split(",")]
|
||||
point = tuple(float(i) for i in p.split(","))
|
||||
assert(len(point)==2)
|
||||
triangle.append( point )
|
||||
triangles.append( triangle )
|
||||
return triangles
|
||||
|
|
|
|||
8
utils.py
8
utils.py
|
|
@ -21,7 +21,7 @@ def load_points( stream ):
|
|||
points = []
|
||||
for line in stream:
|
||||
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)
|
||||
points.append( p )
|
||||
return points
|
||||
|
|
@ -36,12 +36,12 @@ def load_segments( stream ):
|
|||
segments = []
|
||||
for line in stream:
|
||||
if line.strip()[0] != "#":
|
||||
seg = line.strip()
|
||||
seg = line.strip().split()
|
||||
assert(len(seg)==2)
|
||||
edge = []
|
||||
for p in seg:
|
||||
assert(len(p)==2)
|
||||
point = tuple([float(i) for i in seg])
|
||||
point = tuple([float(i) for i in p.split(",")])
|
||||
assert(len(point)==2)
|
||||
edge.append( point )
|
||||
segments.append( edge )
|
||||
return segments
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ def dual( triangles ):
|
|||
|
||||
for triangle in triangles:
|
||||
assert( len(triangle) == 3 )
|
||||
# if not triangulation.is_acute(triangle):
|
||||
# print triangle
|
||||
assert( triangulation.is_acute(triangle) )
|
||||
current_node = triangulation.circumcircle(triangle)[0]
|
||||
assert( len(current_node) == 2 )
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue