Datasets:

License:
File size: 1,418 Bytes
76cb30c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
def rectangular_triangles(x_count, y_count, x_origin, y_origin, width, height):
    nodes = np.zeros((x_count * y_count, 2), dtype=np.float64)
    elements = np.zeros((2 * (x_count - 1) * (y_count - 1), 3), dtype=np.int32)
    points_x = np.linspace(x_origin, x_origin + width, num=x_count)
    points_y = np.linspace(y_origin, y_origin + height, num=y_count)
    cx = x_origin + width / 2.0
    cy = y_origin + height / 2.0
    for i in range(x_count):
        for j in range(y_count):
            nodes[i * y_count + j, 0] = points_x[i]
            nodes[i * y_count + j, 1] = points_y[j]
    for i in range(x_count - 1):
        for j in range(y_count - 1):
            bl = i * y_count + j
            br = (i + 1) * y_count + j
            tr = (i + 1) * y_count + (j + 1)
            tl = i * y_count + (j + 1)
            all_right_top = np.all(nodes[[bl, br, tr, tl], 0] >= cx) and np.all(nodes[[bl, br, tr, tl], 1] >= cy)
            all_left_bottom = np.all(nodes[[bl, br, tr, tl], 0] <= cx) and np.all(nodes[[bl, br, tr, tl], 1] <= cy)
            elem_idx = 2 * (i * (y_count - 1) + j)
            if all_right_top or all_left_bottom:
                elements[elem_idx] = [bl, br, tl]
                elements[elem_idx + 1] = [br, tr, tl]
            else:
                elements[elem_idx] = [bl, br, tr]
                elements[elem_idx + 1] = [bl, tr, tl]
    return nodes, elements