File size: 2,117 Bytes
f9b644c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Debug 7-vertex optimization.
"""

import numpy as np
import torch
from ideal_poly_volume_toolkit.geometry import (
    delaunay_triangulation_indices,
    triangle_volume_from_points_torch,
)

# Test a simple configuration
z1 = complex(0, 0)
z2 = complex(1, 0)
z4 = complex(-1, 0)
z5 = complex(0, -1)
z6 = complex(0.5, 0.5)
z7 = complex(-0.5, -0.5)

complex_points = [z1, z2, z3, z4, z5, z6, z7]
Z_np = np.array(complex_points, dtype=np.complex128)
points_2d = np.column_stack([Z_np.real, Z_np.imag])

print("Testing 7-vertex configuration:")
print(f"Points shape: {points_2d.shape}")
print(f"Points:\n{points_2d}")

try:
    idx = delaunay_triangulation_indices(points_2d)
    print(f"\nDelaunay triangulation successful!")
    print(f"Number of triangles: {len(idx)}")
    print(f"Triangles: {idx}")
    
    # Compute volume
    Z_torch = torch.tensor(Z_np, dtype=torch.complex128)
    total_volume = 0
    for i, (a, b, c) in enumerate(idx):
        vol = triangle_volume_from_points_torch(Z_torch[a], Z_torch[b], Z_torch[c], series_terms=96)
        total_volume += vol.item()
        print(f"  Triangle {i} ({a},{b},{c}): volume = {vol.item():.6f}")
    
    print(f"\nTotal volume: {total_volume:.6f}")
    
except Exception as e:
    print(f"\nError: {e}")
    print(f"Error type: {type(e)}")

# Now test with just 4 points (should work)
print("\n" + "="*50)
print("Testing 4-vertex configuration (tetrahedron):")
z1 = complex(0, 0)
z2 = complex(1, 0)
z4 = complex(0.5, 0.5)

complex_points = [z1, z2, z3, z4]
Z_np = np.array(complex_points, dtype=np.complex128)
points_2d = np.column_stack([Z_np.real, Z_np.imag])

try:
    idx = delaunay_triangulation_indices(points_2d)
    print(f"Number of triangles: {len(idx)}")
    
    Z_torch = torch.tensor(Z_np, dtype=torch.complex128)
    total_volume = 0
    for i, (a, b, c) in enumerate(idx):
        vol = triangle_volume_from_points_torch(Z_torch[a], Z_torch[b], Z_torch[c], series_terms=96)
        total_volume += vol.item()
    
    print(f"Total volume: {total_volume:.6f}")
    
except Exception as e:
    print(f"Error: {e}")