forked from tnakaicode/PlotDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_gyroid.py
More file actions
48 lines (37 loc) · 1.47 KB
/
plot_gyroid.py
File metadata and controls
48 lines (37 loc) · 1.47 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
import numpy as np
import math
from OCC.Display.SimpleGui import init_display
from OCC.Core.gp import gp_Pnt
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire
from OCC.Core.TColgp import TColgp_Array2OfPnt
from OCC.Core.GeomAPI import GeomAPI_PointsToBSplineSurface
from OCC.Core.GeomAbs import GeomAbs_C2
from OCC.Core.GeomAbs import GeomAbs_Intersection
from OCC.Core.BRepOffset import BRepOffset_MakeOffset, BRepOffset_Skin
from base import plotocc
def gyroid(x, y, z, t):
return np.cos(x) * np.sin(y) + np.cos(y) * np.sin(z) + np.cos(z) * np.sin(x) - t
if __name__ == '__main__':
obj = plotocc()
lat = 2.0
res = 11
pt = 3.0
x, y, z = np.pi / 2. * np.mgrid[-1:1:res *
1j, -1:1:res * 1j, -1:1:res * 1j] * lat
vol = gyroid(x, y, z, pt)
print(vol.shape[-1])
for iz, vz in enumerate(vol[::, ]):
print(iz)
ixy = vz.shape
pts = TColgp_Array2OfPnt(1, ixy[0], 1, ixy[1])
for idx, val in np.ndenumerate(vz):
ix, iy = idx[0], idx[1]
px, py, pz = x[ix, iy, iz], y[ix, iy, iz], val
pnt = gp_Pnt(px, py, pz)
# display.DisplayShape(pnt)
pts.SetValue(ix + 1, iy + 1, pnt)
crve = GeomAPI_PointsToBSplineSurface(
pts, 3, 8, GeomAbs_C2, 0.001).Surface()
face = BRepBuilderAPI_MakeFace(crve, 1e-6).Face()
obj.display.DisplayShape(face)
obj.show()