clean triangulation subfunctions
Get ride of the logical operator and use cleaner bounding notation. Add exclude_edges to is_acute.
This commit is contained in:
parent
634ed47f42
commit
2c2d6b2d40
1 changed files with 6 additions and 9 deletions
|
|
@ -104,23 +104,20 @@ 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)
|
||||
# If all of alpha, beta, and gamma are strictly in ]0,1[,
|
||||
# then the point p0 strictly lies within the triangle.
|
||||
return any( x <= 0 or 1 <= x for x in (alpha, beta, gamma) )
|
||||
return all( 0 < x < 1 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) )
|
||||
# If the inequality is not strict, then the point may lies on an edge.
|
||||
return all( 0 <= x <= 1 for x in (alpha, beta, gamma) )
|
||||
|
||||
|
||||
def is_acute(triangle):
|
||||
def is_acute(triangle, exclude_edges = False ):
|
||||
"""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 )
|
||||
|
||||
return in_triangle( circumcircle(triangle)[0], triangle, exclude_edges )
|
||||
|
||||
|
||||
def bounds( vertices ):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue