drufat / triangle

Python bindings to the triangle library
GNU Lesser General Public License v3.0
236 stars 54 forks source link

No Response when Triangulating Section #81

Closed CHDYZ2023 closed 1 month ago

CHDYZ2023 commented 4 months ago

I encountered an issue while attempting to triangulate a section using triangle. triangulate(ini_info_0, "pAXao2"). The function did not respond as expected.

Below is the code snippet for the ‘ini_info_0’ variable used in the triangulation, along with the code to inspect the ‘ini_info_0’ information:

# in python 3.9.13 64-bit
import triangle
import matplotlib.pyplot as plt

# 0. Plot function to view information about each point in ini_info_0
# 0.1 Connect the points given into a line

def plot_points_with_lines(points, ifshow = False):

    x = [point[0] for point in points]
    y = [point[1] for point in points]

    for i in range(len(points) - 1):
        plt.plot([points[i][0], points[i+1][0]], [points[i][1], points[i+1][1]], color='red')

    plt.title('Plot of Points with Lines')
    plt.xlabel('X-axis')
    plt.ylabel('Y-axis')

    if ifshow:
        plt.show()

# 0.2 Mark points numerically in order
def plot_points_with_order(points, 
                           color: str = 'blue', 
                           label: str = '1',
                           size: int = 20, 
                           ifshow = False):

    x = [point[0] for point in points]
    y = [point[1] for point in points]

    plt.scatter(x, y, color = color, label = label, s = size)

    for i, txt in enumerate(points):
        plt.annotate(f'{i}', (x[i], y[i]), textcoords = "offset points", xytext = (0,10), ha = 'center')

    plt.title('Scatter Plot of Points with Markers')
    plt.xlabel('X-axis')
    plt.ylabel('Y-axis')

    plt.legend()

    if ifshow:
        plt.show()

# 1. Main problem
# 1.0 Initial geometry information that can't be meshed
ini_info_0 = {'vertices': [(175.0, 175.0), (175.0, -175.0), (-175.0, -175.0), (-175.0, 175.0), (150.0, 150.0), (150.0, -150.0), (-150.0, -150.0), (-150.0, 150.0), (-84.85, 127.28), (0.0, 42.43), (84.85, 127.28), (127.28, 84.85), (42.43, 0.0), (127.28, -84.85), (84.85, -127.28), (0.0, -42.43), (-84.85, -127.28), (-127.28, -84.85), (-42.43, -0.0), (-127.28, 84.85), (77.78, 120.21), (96.17, 101.82), (18.38, 24.04), (24.04, 18.38), (101.82, 96.17), (120.21, 77.78), (120.21, -77.78), (101.82, -96.17), (24.04, -18.38), (18.38, -24.04), (96.17, -101.82), (77.78, -120.21), (-77.78, -120.21), (-96.17, -101.82), (-18.38, -24.04), (-24.04, -18.38), (-101.82, -96.17), (-120.21, -77.78), (-120.21, 77.78), (-101.82, 96.17), (-24.04, 18.38), (-18.38, 24.04), (-96.17, 101.82), (-77.78, 120.21), (0.0, 5.66), (5.66, 0.0), (0.0, -5.66), (-5.66, -0.0)], 
              'segments': [(0, 1), (1, 2), (2, 3), (3, 0), (4, 5), (5, 6), (6, 7), (7, 4), (4, 5), (5, 6), (6, 7), (7, 4), (8, 9), (9, 10), (10, 11), (11, 12), (12, 13), (13, 14), (14, 15), (15, 16), (16, 17), (17, 18), (18, 19), (19, 8), (9, 20), (20, 21), (21, 22), (22, 9), (23, 24), (24, 25), (25, 12), (12, 23), (12, 26), (26, 27), (27, 28), (28, 12), (29, 30), (30, 31), (31, 15), (15, 29), (15, 32), (32, 33), (33, 34), (34, 15), (35, 36), (36, 37), (37, 18), (18, 35), (18, 38), (38, 39), (39, 40), (40, 18), (41, 42), (42, 43), (43, 9), (9, 41), (41, 9), (9, 22), (22, 44), (44, 41), (23, 12), (12, 28), (28, 45), (45, 23), (29, 15), (15, 34), (34, 46), (46, 29), (35, 18), (18, 40), (40, 47), (47, 35), (44, 21), (21, 20), (20, 10), (10, 11), (11, 25), (25, 24), (24, 45), (45, 45), (45, 27), (27, 26), (26, 13), (13, 14), (14, 31), (31, 30), (30, 46), (46, 46), (46, 33), (33, 32), (32, 16), (16, 17), (17, 37), (37, 36), (36, 47), (47, 47), (47, 39), (39, 38), (38, 19), (19, 8), (8, 43), (43, 42), (42, 44)], 
              'holes': [(55.87954116297085, -50.2241991870295), (55.879541162970845, 50.2241991870295), (50.2245904118822, -55.879932347143), (50.224590411882204, 55.879932347143), (-50.224590411882204, -55.879932347143), (-50.2245904118822, 55.879932347143), (-55.879541162970845, -50.2241991870295), (-55.87954116297085, 50.2241991870295)], 
              'regions': [[-162.5, 0.0, 0, 100], [-106.82249999999999, 21.215, 1, 100], [48.08309109025457, 72.125, 2, 100], [72.12309101426918, 48.08, 3, 100], [72.12309101426918, -48.08, 4, 100], [48.08309109025457, -72.125, 5, 100], [-48.08309109025457, -72.125, 6, 100], [-72.12309101426918, -48.08, 7, 100], [-72.12309101426918, 48.08, 8, 100], [-48.08309109025457, 72.125, 9, 100], [1.7763568394002505e-15, 33.235, 10, 100], [24.0425, 9.19, 11, 100], [-1.7763568394002505e-15, -33.235, 12, 100], [-24.0425, 9.19, 13, 100], [-4.440892098500626e-15, 2.83, 14, 100]]}

# 1.1 Plot the points(vertices, holes and regions) and lines(segments)
# 1.1.0 segments
current_mesh = ini_info_0
for i in range(len(current_mesh['segments'])):
    sttpt = current_mesh['vertices'][current_mesh['segments'][i][0]]
    endpt = current_mesh['vertices'][current_mesh['segments'][i][1]]

    plot_points_with_lines([sttpt, endpt])

# 1.1.1 regions
pts = []
for i in current_mesh['regions']:
    x = i[0]
    y = i[1]
    pts.append([x, y])
plot_points_with_order(pts, 'red', 'regions', 80)

# 1.1.2 holes
for i in current_mesh['holes']:
    x = i[0]
    y = i[1]
    pts.append([x, y])
plot_points_with_order(pts, 'blue', 'holes')

# 1.1.3 vertices
d = []
for i in range(len(current_mesh['vertices'])):
    pt = [current_mesh['vertices'][i][0], current_mesh['vertices'][i][1]]
    d.append(pt)
plot_points_with_order(d, 'green', 'vertices')

plt.show()
# In the figure, 'holes' overlaps with 'regions' at some points

# mesh
# when option is
# "pq30Aao2": no response and flashed back
# "pAao2"   : Error:  Ran out of precision at (-83.4366165876, 41.0066165876).
#             I attempted to split a segment to a smaller size than can be accommodated by the finite precision of floating point arithmetic.
#             Try increasing the area criterion and/or reducing the minimum allowable angle so that tiny triangles are not created.
# "pAXao2"  : Internal error in insertsegment():  Unable to locate PSLG vertex (-42.43, -0) in triangulation.
#             Please report this bug to jrs@cs.berkeley.edu
#             Include the message above, your input data set, and the exact command line you used to run Triangle.
mesh = triangle.triangulate(ini_info_0, "pAXao2")
print(mesh)

2024-06-22 152240 Geometric information check

2024-06-22 160043 Unexpected results

2024-06-22 160248 Expected results

Please investigate this issue further. Thank you.