from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir, gp_Ax2, gp_Pln, gp_Ax3, gp_Trsf, gp_Ax1
from OCC.Display.backend import load_backend
load_backend('qt-pyqt5')
from OCC.Display.SimpleGui import init_display
from OCC.Core.gp import gp_Ax2, gp_Pnt, gp_Dir, gp_Pnt2d
from OCC.Core.TopoDS import TopoDS_Compound, TopoDS_Builder, topods, TopoDS_Face, TopoDS_Shape
from OCC.Display.OCCViewer import rgb_color
from OCC.Core.TopoDS import topods, TopoDS_Compound, TopoDS_Face
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Extend.ShapeFactory import translate_shp
import numpy as np
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.OCCViewer import rgb_color
#长方体
def xx():
sanwei_box = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 1, 1, 1).Shape() # 每个填充快
aDSC_save = TopoDS_Compound() # 定义一个复合体
aBuilder = TopoDS_Builder() # 建立一个TopoDS_Builder()
aBuilder.MakeCompound(aDSC_save) # 生成一个复合体DopoDS_shape
a=10
num=100
# tt = np.linspace(0, 2 * np.pi, 1024)
tt = np.linspace(0, 2 * np.pi,num)
for x in range(num):
t=tt[x]
# y = .25 * (x + 4.) * (x + 1.) * (x- 2.)
# x = a * (2 * np.cos(t) - np.cos(2 * t))
# z = a * (2 * np.sin(t) - np.sin(2 * t))
x = 10*np.sin(t)
y = 10*np.cos(t)
z = 10*np.tan(t+2)
aDSC_one_add = translate_shp(sanwei_box, gp_Vec(x, y, z))
aBuilder.Add(aDSC_save, aDSC_one_add) # 加进去
display.DisplayShape(aDSC_save, update=True, color=rgb_color(0, 0, 1)) # l
display.FitAll()
if __name__ == "__main__":
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()
xx()
start_display()
```python
在这里插入图片描述
```python
def shuangluoxuan():
n_num = 1024
# tt = np.linspace(0, 2 * np.pi, 1024)
quxian_x = np.linspace(-4, 4, n_num)
for x in range(n_num):
X =quxian_x [x]
Y = .25 * (X + 4.) * (X + 1.) * (X - 2.)
Z=0
aDSC_one_add = translate_shp(sanwei_box, gp_Vec(X, Y, Z))
aBuilder.Add(aDSC_save, aDSC_one_add) # 加进去
display.DisplayShape(aDSC_save, update=True, color=rgb_color(0, 0, 1)) # l
display.FitAll()
shuangluoxuan()
def shuangluoxuan_sigm():
n_num = 200
# tt = np.linspace(0, 2 * np.pi, 1024)
quxian_x = np.arange(-10, 10, 0.1)
for x in range(n_num):
X = quxian_x[x]
Y = 1 / (1 + math.exp(-X))
Z=0
# y.append(y_1)
aDSC_one_add = translate_shp(sanwei_box, gp_Vec(X, Y, Z))
aBuilder.Add(aDSC_save, aDSC_one_add) # 加进去
display.DisplayShape(aDSC_save, update=True, color=rgb_color(0, 0, 1)) # l
display.FitAll()
def shuangluoxuan_peaks():
n_num = 1024
# quxian_x = np.linspace(0, np.pi/100, 1024)
quxian_x = np.linspace(0, 2*np.pi, n_num) #0: pi / 100:pi * 10
for m in ![在这里插入图片描述](https://img-blog.csdnimg.cn/0bec37c9d0864524913cb79f9ee807c4.png)
range(20):
for x in range(n_num):
X = quxian_x[x]+m
# X= math.sin(X)
Y =0
Y = math.cos(X)+m
Z = 0
Z = 3*(1-X)**2.*math.exp(-(X**2) - (Y+1)**2) - 10*(X/5 - X**3 - Y**5) * math.exp(-X**2-Y**2)- 1/3*math.exp(-(X+1)**2 - Y**2)
# y.append(y_1)
aDSC_one_add = translate_shp(sanwei_box, gp_Vec(X, Y, Z))
aBuilder.Add(aDSC_save, aDSC_one_add) # 加进去
display.DisplayShape(aDSC_save, update=True, color=rgb_color(0, 0, 1)) # l
display.FitAll()
def luoxuan_shengxian():
sanwei_box = BRepPrimAPI_MakeBox(gp_Pnt(0, 0, 0), 1, 1, 1).Shape() # 每个填充快
aDSC_save = TopoDS_Compound() # 定义一个复合体
aBuilder = TopoDS_Builder() # 建立一个TopoDS_Builder()
aBuilder.MakeCompound(aDSC_save) # 生成一个复合体DopoDS_shape
a=10
num_m=100
num_n = 100
# tt = np.linspace(0, 2 * np.pi, 1024)
theta_m = np.linspace(-4 * np.pi, 4 * np.pi, num_m)
theta_n = np.linspace(-2, 2, 100)
for m in range(num_m):
t=theta_m[m]
for n in range(num_n):
z=100*theta_n[n]
r = z ** 2 + 1+100
x = r * np.sin(t)
y = r * np.cos(t)
gp_t=gp_Vec(x, y, z)
aDSC_one_add = translate_shp(sanwei_box,gp_t )
aBuilder.Add(aDSC_save, aDSC_one_add) # 加进去
display.DisplayShape(aDSC_save, update=True, color=rgb_color(0, 0, 1)) # l
display.FitAll()