-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_geometry_analysis.py
More file actions
64 lines (48 loc) · 1.85 KB
/
Copy path02_geometry_analysis.py
File metadata and controls
64 lines (48 loc) · 1.85 KB
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
"""
Surface, curve, and topology analysis.
Run with the `pyocc` conda environment active:
python examples/02_geometry_analysis.py
"""
import numpy as np
from pyocc.edge import Edge
from pyocc.solid import Solid
def analyze_faces(box):
print("Face analysis")
print("-------------")
for i, face in enumerate(box.faces()):
# Evaluate the surface at the centre of its UV domain.
u_min, u_max, v_min, v_max = face.uv_bounds()
u_mid, v_mid = 0.5 * (u_min + u_max), 0.5 * (v_min + v_max)
point = face.point(np.array([u_mid, v_mid]))
normal = face.normal(np.array([u_mid, v_mid]))
print(
f" face {i}: area={face.area():7.2f} centre={np.round(point, 2)} "
f"normal={np.round(normal, 2)}"
)
def closest_point(box):
print("\nClosest-point query")
print("-------------------")
datum = np.array([20.0, 0.0, 0.0]) # outside the 10x20x30 box (max X = 10)
point, element, distance = box.find_closest_point_data(datum)
print(f" datum : {datum}")
print(f" closest : {np.round(point, 3)}")
print(f" distance : {distance:.3f}")
print(f" on a : {type(element).__name__}")
def analyze_edges():
print("\nCurve analysis")
print("--------------")
line = Edge.make_line_from_points(np.array([0, 0, 0]), np.array([10, 10, 0]))
print(f" line type : {line.curve_type()} length={line.length():.4f}")
print(f" midpoint : {np.round(line.point(line.u_bounds().middle()), 3)}")
circle = Edge.make_circle(center=np.array([0, 0, 0]), radius=5.0)
print(
f" circle type : {circle.curve_type()} length={circle.length():.4f} "
f"(2*pi*r = {2 * np.pi * 5:.4f})"
)
def main():
box = Solid.make_box(10, 20, 30)
analyze_faces(box)
closest_point(box)
analyze_edges()
if __name__ == "__main__":
main()