沈阳建设银行网站网站定制一般价格多少
沈阳建设银行网站,网站定制一般价格多少,网络营销的盈利模式,一键分享到wordpressplotly3D #xff08;3d charts in Python#xff09;可以画3维图形
在做圆柱的3D装箱项目#xff0c;需要装箱的可视化#xff0c;但是Mesh #xff08;3d mesh plots in Python#xff09;只能画三角形#xff0c;所以需要用多个三角形拼成一个圆柱#xff08;想做立…plotly3D 3d charts in Python可以画3维图形
在做圆柱的3D装箱项目需要装箱的可视化但是Mesh 3d mesh plots in Python只能画三角形所以需要用多个三角形拼成一个圆柱想做立方体的可视化可以进入使用plotly dash 画3d立方体_python 3d绘图立方体-CSDN博客
1 画上下底面的边线因为只能画直线所以只能用n边形代替圆我感觉30-50就足够了 # 找圆柱底边 num_points 个点
def to_cylinder_point(cylinder:Cylinder):print(cylinder)# 设置圆形参数num_points 30 # 圆形上的点的数量# 计算圆上的点的坐标theta np.linspace(0, 2 * np.pi, num_points)x cylinder.coordinate[0] cylinder.radius * np.cos(theta)y cylinder.coordinate[1] cylinder.radius * np.sin(theta)z_underside np.full(num_points, cylinder.coordinate[2]) z_top np.full(num_points, cylinder.coordinate[2]cylinder.height)return x,y,z_underside,z_top
# 画出下底边的轮廓
fig.add_scatter3d(xx, yy, zz_bottom, modelines, line{color: black, width: 2})
2 拼上下底面以上下底面圆心为中心上一步计算出来的“圆柱底边 num_points 个点”做边画三角形。 # 将圆心插入首位b_x np.insert(x,0,p.coordinate[0])b_y np.insert(y,0,p.coordinate[1])b_z np.insert(z_bottom,0,p.coordinate[2])t_z np.insert(z_top, 0, p.coordinate[2] p.height)i, j, k to_planes(len(b_x))# 画底面fig.add_mesh3d(xb_x,yb_y,zb_z,ii,jj,kk,colorpink)# 画顶面fig.add_mesh3d(xb_x,yb_y,zt_z,ii,jj,kk,colorpink)
3 拼侧面以上一步计算出来的 上下“圆柱底边 各num_points 个点”做边画三角形。 s_x np.concatenate((x,x))s_y np.concatenate((y,y))s_z np.concatenate((z_top,z_bottom))ii, jj, kk to_side(len(s_z))# 画侧面fig.add_mesh3d(xs_x,ys_y,zs_z,iii,jjj,kkk,colorpink)
所有代码
import plotly.graph_objects as go
import numpy as np
import mathclass Cylinder:def __init__(self, name, diameter,height,num 0):self.name nameself.diameter int(diameter)self.radius int(diameter/2)self.height int(height)self.num numself.coordinate Nonedef cylinder_copy(cylinder:Cylinder,height):new_cylinder Cylinder(cylinder.name,cylinder.diameter,cylinder.height,cylinder.num)new_cylinder.coordinate cylinder.coordinate[height]return new_cylinderclass Box:def __init__(self, name, long,wide,height):self.name nameself.long int(long)self.wide int(wide)self.height int(height)def toline(cx,cy,cz):# 通过立方体的8个顶点画出立方体的轮廓.cx(x轴8个坐标)x [cx[0],cx[1],cx[2],cx[3],cx[0],cx[4],cx[5],cx[1],cx[5],cx[6],cx[2],cx[6],cx[7],cx[3],cx[7],cx[4]]y [cy[0],cy[1],cy[2],cy[3],cy[0],cy[4],cy[5],cy[1],cy[5],cy[6],cy[2],cy[6],cy[7],cy[3],cy[7],cy[4]]z [cz[0],cz[1],cz[2],cz[3],cz[0],cz[4],cz[5],cz[1],cz[5],cz[6],cz[2],cz[6],cz[7],cz[3],cz[7],cz[4]]return x,y,zdef toxyz(begin,end):# 通过开始结束位置确定立方体的8个顶点# 0 1 2 3 4 5 6 7x [begin[0],begin[0],end[0],end[0],begin[0],begin[0],end[0],end[0]]y [begin[1],end[1],end[1],begin[1],begin[1],end[1],end[1],begin[1]]z [begin[2],begin[2],begin[2],begin[2],end[2],end[2],end[2],end[2]]return x,y,z# 根据圆的边线填满圆
def to_planes(n):ii[]jj[]kk[]for v in range(1,n):ii.append(0)jj.append(v)if v1n:kk.append(1)else:kk.append(v1)return ii,jj,kk# 根据圆上下底面的边线填满侧边
def to_side(n):ii[]jj[]kk[]half int(n/2)for i in range(half):ii.append(i)if i1half:jj.append(0)else:jj.append(i1)kk.append(ihalf)if i1half:ii.append(0)else:ii.append(i1)jj.append(ihalf)if ihalf1n:kk.append(half)else:kk.append(ihalf1)return ii,jj,kkdef to_cylinder_point(cylinder:Cylinder):print(cylinder)# 设置圆形参数num_points 30 # 圆形上的点的数量# 计算圆上的点的坐标theta np.linspace(0, 2 * np.pi, num_points)x cylinder.coordinate[0] cylinder.radius * np.cos(theta)y cylinder.coordinate[1] cylinder.radius * np.sin(theta)z_underside np.full(num_points, cylinder.coordinate[2]) # 在 z 轴上的坐标都为圆心的 z 坐标z_top np.full(num_points, cylinder.coordinate[2]cylinder.height) # 在 z 轴上的坐标都为圆心的 z 坐标return x,y,z_underside,z_topdef getfig(box:Box,position):box_xyz toxyz([0, 0, 0], [box.long, box.wide, box.height])box_line toline(box_xyz[0], box_xyz[1], box_xyz[2])figgo.Figure(data[go.Scatter3d(xbox_line[0],ybox_line[1],zbox_line[2],modelines,line{color: black, width: 2})])for p in position:x, y, z_bottom, z_top to_cylinder_point(p)# 画下底面的线fig.add_scatter3d(xx, yy, zz_bottom, modelines, line{color: black, width: 2})# 画顶面的线fig.add_scatter3d(xx, yy, zz_top, modelines, line{color: black, width: 2})b_x np.insert(x,0,p.coordinate[0])b_y np.insert(y,0,p.coordinate[1])b_z np.insert(z_bottom,0,p.coordinate[2])t_z np.insert(z_top, 0, p.coordinate[2] p.height)i, j, k to_planes(len(b_x))# 画底面fig.add_mesh3d(xb_x,yb_y,zb_z,ii,jj,kk,colorpink)# 画顶面fig.add_mesh3d(xb_x,yb_y,zt_z,ii,jj,kk,colorpink)s_x np.concatenate((x,x))s_y np.concatenate((y,y))s_z np.concatenate((z_top,z_bottom))ii, jj, kk to_side(len(s_z))# 画侧面fig.add_mesh3d(xs_x,ys_y,zs_z,iii,jjj,kkk,colorpink)fig.update_layout(clickmodeeventselect,# 设置xyz轴比例原本比例draw axes in proportion to the proportion of their rangesscene_aspectmodedata,scenedict(xaxis_titlex-长str(box.long)mm,yaxis_titley-宽str(box.wide)mm,zaxis_titlez-高str(box.height)mm,xaxisdict(backgroundcolorrgb(230, 230,200),gridcolorwhite,showbackgroundTrue,zerolinecolorblack, ),yaxisdict(backgroundcolorrgb(230, 230,200),gridcolorwhite,showbackgroundTrue,zerolinecolorblack),zaxisdict(backgroundcolorrgb(230, 230,200),gridcolorwhite,showbackgroundTrue,zerolinecolorblack, ),),height600,width800,)return figcylinder Cylinder(a,70,30)
cylinder.coordinate[502*math.sqrt(3),70,10]box Box(b,100,200,70)
fig getfig(box,[cylinder])
fig.show()
代码结果展示 多个圆柱展示
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/87982.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!