先上效果图:

import sys
from math import pi as M_PI, sin, cos, atanfrom OCC.Core.gp import (gp_Pnt2d, gp_Ax2d, gp_Dir2d, gp_Circ2d, gp_Origin2d, gp_DX2d,gp_Ax2, gp_OX2d, gp_Lin2d, gp_Trsf, gp_XOY,gp_Pnt, gp_Vec, gp_Ax3, gp_Pln, gp_Origin, gp_DX, gp_DY,gp_DZ, gp_OZ)
from OCC.Core.GCE2d import GCE2d_MakeArcOfCircle, GCE2d_MakeCircle, GCE2d_MakeLine
from OCC.Core.Geom2dAPI import Geom2dAPI_InterCurveCurve
from OCC.Core.Geom2d import Geom2d_TrimmedCurve
from OCC.Core.GeomAPI import geomapi_To3d
from OCC.Core.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge,BRepBuilderAPI_MakeWire,BRepBuilderAPI_MakeFace,BRepBuilderAPI_Transform)
from OCC.Core.BRepPrimAPI import (BRepPrimAPI_MakePrism, BRepPrimAPI_MakeRevol,BRepPrimAPI_MakeCylinder, BRepPrimAPI_MakeCone)
from OCC.Core.GccAna import GccAna_Circ2d2TanRad
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut, BRepAlgoAPI_Fuse
from OCC.Core.BRepFilletAPI import BRepFilletAPI_MakeFillet2d
from OCC.Core.BRepTools import BRepTools_WireExplorer
from OCC.Display.SimpleGui import init_displayroller_diameter = 10.2
pitch = 15.875
num_teeth = 40
chain_width = 6.35#  Dimensions derived from the provided inputs
roller_radius = roller_diameter / 2.
tooth_angle = (2 * M_PI) / num_teeth
pitch_circle_diameter = pitch / sin(tooth_angle / 2.)
pitch_circle_radius = pitch_circle_diameter / 2.roller_contact_angle_min = (M_PI * 120 / 180) - ((M_PI / 2.) / num_teeth)
roller_contact_angle_max = (M_PI * 140 / 180) - ((M_PI / 2.) / num_teeth)
roller_contact_angle = (roller_contact_angle_min + roller_contact_angle_max) / 2.tooth_radius_min = 0.505 * roller_diameter
tooth_radius_max = tooth_radius_min + (0.069 * pow(roller_diameter, 1.0 / 3.0))
tooth_radius = (tooth_radius_min + tooth_radius_max) / 2.profile_radius = 0.12 * roller_diameter * (num_teeth + 2)
top_diameter = pitch_circle_diameter + ((1 - (1.6 / num_teeth)) * pitch) - roller_diameter
top_radius = top_diameter / 2.thickness = chain_width * 0.95# Center hole data
center_radius = 125.0 / 2.# Mounting hole data
mounting_hole_count = 6
mounting_radius = 153.0 / 2.
hole_radius = 8.5 / 2.def build_tooth():base_center = gp_Pnt2d(pitch_circle_radius + (tooth_radius - roller_radius), 0)base_circle = gp_Circ2d(gp_Ax2d(base_center, gp_Dir2d()), tooth_radius)trimmed_base = GCE2d_MakeArcOfCircle(base_circle,M_PI - (roller_contact_angle / 2.),M_PI).Value()trimmed_base.Reverse()  # just a trickp0 = trimmed_base.StartPoint()p1 = trimmed_base.EndPoint()# Determine the center of the profile circlex_distance = cos(roller_contact_angle / 2.) * (profile_radius + tooth_radius)y_distance = sin(roller_contact_angle / 2.) * (profile_radius + tooth_radius)profile_center = gp_Pnt2d(pitch_circle_radius - x_distance, y_distance)# Construct the profile circle gp_Circ2dprofile_circle = gp_Circ2d(gp_Ax2d(profile_center, gp_Dir2d()),profile_center.Distance(p1))geom_profile_circle = GCE2d_MakeCircle(profile_circle).Value()# Construct the outer circle gp_Circ2douter_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius)geom_outer_circle = GCE2d_MakeCircle(outer_circle).Value()inter = Geom2dAPI_InterCurveCurve(geom_profile_circle, geom_outer_circle)num_points = inter.NbPoints()assert isinstance(p1, gp_Pnt2d)if num_points == 2:if p1.Distance(inter.Point(1)) < p1.Distance(inter.Point(2)):p2 = inter.Point(1)else:p2 = inter.Point(2)elif num_points == 1:p2 = inter.Point(1)else:sys.exit(-1)# Trim the profile circle and mirrortrimmed_profile = GCE2d_MakeArcOfCircle(profile_circle, p1, p2).Value()# Calculate the outermost pointp3 = gp_Pnt2d(cos(tooth_angle / 2.) * top_radius,sin(tooth_angle / 2.) * top_radius)# and use it to create the third arctrimmed_outer = GCE2d_MakeArcOfCircle(outer_circle, p2, p3).Value()# Mirror and reverse the three arcsmirror_axis = gp_Ax2d(gp_Origin2d(), gp_DX2d().Rotated(tooth_angle / 2.))mirror_base = Geom2d_TrimmedCurve.DownCast(trimmed_base.Copy())mirror_profile = Geom2d_TrimmedCurve.DownCast(trimmed_profile.Copy())mirror_outer = Geom2d_TrimmedCurve.DownCast(trimmed_outer.Copy())mirror_base.Mirror(mirror_axis)mirror_profile.Mirror(mirror_axis)mirror_outer.Mirror(mirror_axis)mirror_base.Reverse()mirror_profile.Reverse()mirror_outer.Reverse()# Replace the two outer arcs with a single oneouter_start = trimmed_outer.StartPoint()outer_mid = trimmed_outer.EndPoint()outer_end = mirror_outer.EndPoint()outer_arc = GCE2d_MakeArcOfCircle(outer_start, outer_mid, outer_end).Value()# Create an arc for the inside of the wedgeinner_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()),top_radius - roller_diameter)inner_start = gp_Pnt2d(top_radius - roller_diameter, 0)inner_arc = GCE2d_MakeArcOfCircle(inner_circle, inner_start, tooth_angle).Value()inner_arc.Reverse()# Convert the 2D arcs and two extra lines to 3D edgesplane = gp_Pln(gp_Origin(), gp_DZ())arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_base, plane)).Edge()arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_profile, plane)).Edge()arc3 = BRepBuilderAPI_MakeEdge(geomapi_To3d(outer_arc, plane)).Edge()arc4 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_profile, plane)).Edge()arc5 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_base, plane)).Edge()p4 = mirror_base.EndPoint()p5 = inner_arc.StartPoint()lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0),gp_Pnt(p5.X(), p5.Y(), 0)).Edge()arc6 = BRepBuilderAPI_MakeEdge(geomapi_To3d(inner_arc, plane)).Edge()p6 = inner_arc.EndPoint()lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6.X(), p6.Y(), 0),gp_Pnt(p0.X(), p0.Y(), 0)).Edge()wire = BRepBuilderAPI_MakeWire(arc1)wire.Add(arc2)wire.Add(arc3)wire.Add(arc4)wire.Add(arc5)wire.Add(lin1)wire.Add(arc6)wire.Add(lin2)face = BRepBuilderAPI_MakeFace(wire.Wire())wedge = BRepPrimAPI_MakePrism(face.Shape(), gp_Vec(0.0, 0.0, thickness))return wedge.Shape()def round_tooth(wedge):round_x = 2.6round_z = 0.06 * pitchround_radius = pitch# Determine where the circle used for rounding has to start and stopp2d_1 = gp_Pnt2d(top_radius - round_x, 0)p2d_2 = gp_Pnt2d(top_radius, round_z)# Construct the rounding circleround_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01)if (round_circle.NbSolutions() != 2):sys.exit(-2)round_circle_2d_1 = round_circle.ThisSolution(1)round_circle_2d_2 = round_circle.ThisSolution(2)if (round_circle_2d_1.Position().Location().Coord()[1] >= 0):round_circle_2d = round_circle_2d_1else:round_circle_2d = round_circle_2d_2# Remove the arc used for roundingtrimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value()# Calculate extra points used to construct linesp1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y())p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y())p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y())p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1)p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1)# Convert the arc and four extra lines into 3D edgesplane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX()))arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge()lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge()lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge()lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge()# Make a wire composed of the edgesround_wire = BRepBuilderAPI_MakeWire(arc1)round_wire.Add(lin1)round_wire.Add(lin2)round_wire.Add(lin3)round_wire.Add(lin4)# Turn the wire into a faceround_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape()# Revolve the face around the Z axis over the tooth anglerounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(), tooth_angle).Shape()# Construct a mirrored copy of the first cutting shapemirror = gp_Trsf()mirror.SetMirror(gp_XOY())mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, True).Shape()# and translate it so that it ends up on the other side of the wedgetranslate = gp_Trsf()translate.SetTranslation(gp_Vec(0, 0, thickness))rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, False).Shape()# Cut the wedge using the first and second cutting shapecut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape()cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape()return cut_2def clone_tooth(base_shape):clone = gp_Trsf()grouped_shape = base_shape# Find a divisor, between 1 and 8, for the number_of teethmultiplier = 1max_multiplier = 1for i in range(0, 8):if num_teeth % multiplier == 0:max_multiplier = i + 1multiplier = max_multiplierfor i in range(1, multiplier):clone.SetRotation(gp_OZ(), -i * tooth_angle)rotated_shape = BRepBuilderAPI_Transform(base_shape, clone, True).Shape()grouped_shape = BRepAlgoAPI_Fuse(grouped_shape, rotated_shape).Shape()# Rotate the basic tooth and fuse togetheraggregated_shape = grouped_shapefor i in range(1, int(num_teeth / multiplier)):clone.SetRotation(gp_OZ(), - i * multiplier * tooth_angle)rotated_shape = BRepBuilderAPI_Transform(grouped_shape, clone, True).Shape()aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape, rotated_shape).Shape()cylinder = BRepPrimAPI_MakeCylinder(gp_XOY(),top_radius - roller_diameter,thickness)aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape,cylinder.Shape()).Shape()return aggregated_shapedef center_hole(base):cylinder = BRepPrimAPI_MakeCylinder(center_radius, thickness).Shape()cut = BRepAlgoAPI_Cut(base, cylinder)return cut.Shape()def mounting_holes(base):result = basefor i in range(0, mounting_hole_count):center = gp_Pnt(cos(i * M_PI / 3) * mounting_radius,sin(i * M_PI / 3) * mounting_radius, 0.0)center_axis = gp_Ax2(center, gp_DZ())cylinder = BRepPrimAPI_MakeCylinder(center_axis, hole_radius,thickness).Shape()result = BRepAlgoAPI_Cut(result, cylinder).Shape()cone = BRepPrimAPI_MakeCone(center_axis,hole_radius + thickness / 2.,hole_radius, thickness / 2.)result = BRepAlgoAPI_Cut(result, cone.Shape()).Shape()return resultdef cut_out(base):outer = gp_Circ2d(gp_OX2d(), top_radius - 1.75 * roller_diameter)inner = gp_Circ2d(gp_OX2d(), center_radius + 0.75 * roller_diameter)geom_outer = GCE2d_MakeCircle(outer).Value()geom_inner = GCE2d_MakeCircle(inner).Value()geom_inner.Reverse()base_angle = (2. * M_PI) / mounting_hole_counthole_angle = atan(hole_radius / mounting_radius)correction_angle = 3 * hole_angleleft = gp_Lin2d(gp_Origin2d(), gp_DX2d())right = gp_Lin2d(gp_Origin2d(), gp_DX2d())left.Rotate(gp_Origin2d(), correction_angle)right.Rotate(gp_Origin2d(), base_angle - correction_angle)geom_left = GCE2d_MakeLine(left).Value()geom_right = GCE2d_MakeLine(right).Value()inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left)inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right)inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right)inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left)if inter_1.Point(1).X() > 0:p1 = inter_1.Point(1)else:p1 = inter_1.Point(2)if inter_2.Point(1).X() > 0:p2 = inter_2.Point(1)else:p2 = inter_2.Point(2)if inter_3.Point(1).X() > 0:p3 = inter_3.Point(1)else:p3 = inter_3.Point(2)if inter_4.Point(1).X() > 0:p4 = inter_4.Point(1)else:p4 = inter_4.Point(2)trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value()trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value()plane = gp_Pln(gp_Origin(), gp_DZ())arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_outer, plane)).Edge()lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0),gp_Pnt(p3.X(), p3.Y(), 0)).Edge()arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_inner, plane)).Edge()lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0),gp_Pnt(p1.X(), p1.Y(), 0)).Edge()cutout_wire = BRepBuilderAPI_MakeWire(arc1)cutout_wire.Add(lin1)cutout_wire.Add(arc2)cutout_wire.Add(lin2)# Turn the wire into a facecutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire())filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face.Face())explorer = BRepTools_WireExplorer(cutout_wire.Wire())while explorer.More():vertex = explorer.CurrentVertex()filleted_face.AddFillet(vertex, roller_radius)explorer.Next()cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(),gp_Vec(0.0, 0.0, thickness)).Shape()result = baserotate = gp_Trsf()for i in range(0, mounting_hole_count):rotate.SetRotation(gp_OZ(), i * 2. * M_PI / mounting_hole_count)rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, True)result = BRepAlgoAPI_Cut(result,rotated_cutout.Shape()).Shape()return resultdef build_sprocket():# create the sprocket modelwedge = build_tooth()rounded_wedge = round_tooth(wedge)basic_disk = clone_tooth(rounded_wedge)cut_disc = center_hole(basic_disk)mountable_disc = mounting_holes(cut_disc)sprocket = cut_out(mountable_disc)return sprocketsprocket_model = build_sprocket()
# display the sprocket

PythonOCC基础使用:opencascade三维建模命令——一个链轮的绘制(很重要)相关推荐

  1. 【python学习】-多张三维图共用一个colorbar(matplotlib绘制)

    多张三维图共用一个colorbar 一张三维图 多张三维图 一张三维图 绘制一张三维图,大概步骤是:导入相关库:生成三维图框,对X,Y数据进行统一网格化,绘制图形,添加colorbar,设置图形其他参 ...

  2. PythonOCC基础使用:曲面建模

    opencascade 提供了基本曲面(平面,圆柱面,锥面,球面),以及Bezier()和B-样条曲面,回转曲面,拉伸和偏移曲面,曲面裁剪后可以得到裁剪曲面(trimmed surface)啊 贝塞尔 ...

  3. pythoncad标注教程_CAD 2014二维三维建模渲染标注基础与提升视频教程

    CAD 2014基础与提升视频教程 课程描述 CAD 2014基础与提升视频教程,偏机械类 学习人群 零基础,室内都可以:CAD制图者,特别是机械制图:机械.建筑.电子行业从业者主图需求:准备转行CA ...

  4. PythonOCC基础使用:建模——基础三维实体(球体,长方体,棱柱/台/锥,圆柱/锥/台,环形)

    下面会列举一些基本三维图形命令: 实现的国产云端CAD www.yuntucad.com 长方体 from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBo ...

  5. 基于OpenCASCADE自制三维建模软件(六)瓶子模型例程

    文章目录 概述 预备知识 模型 规格 一.构建轮廓 定义支持点 定义几何图形 定义拓扑结构 完成轮廓 二.构建瓶身 拉伸轮廓 倒角 添加瓶颈 创造中空的实体 三.构建螺纹 创建表面 定义二维曲线 创建 ...

  6. 想做次世代三维建模师?先来提高自身美术基础

    关于想要做次世代三维建模,需不需要有美术基础,需要什么样的美术基础,不仅仅是你,也是每个入门新手需要担心的事情. 美术基础重要,软件基础同样重要,两者必不可少. 软件的掌握是你入行必备的技能,美术概念 ...

  7. 计算机学3d建模吗,计算机三维建模与动画基础

    计算机三维建模与动画基础 语音 编辑 锁定 讨论 上传视频 <计算机三维建模与动画基础>是2008年清华大学出版社出版的图书,作者是张烈,骆春慧. 书    名 计算机三维建模与动画基础 ...

  8. 基于OpenCASCADE自制三维建模软件(十一)使用ASSIMP导入导出

    基于OpenCASCADE自制三维建模软件(十一)使用ASSIMP导入导出 2019年08月06日 23:54:20 Jelly_Lee2 阅读数 73 文章标签: 三维建模CADOpenCASCAD ...

  9. 达州计算机cad培训,达州CAD三维建模培训cad三维建模基础视频

    达州CAD三维建模培训cad三维建模基础视频 (1)用户也不能对象的质量.重心.体积.惯性矩等物理特性,不能进行布尔运算.图11-1显示了立体的线框模型,在消隐模式下也看到后面的线.但线框模型结构简单 ...

最新文章

  1. WINDOWS SERVER 2003从入门到精通之配置DHCP服务器(下)
  2. 双击Jar的启动方法
  3. 有关 iOS 的开发证书、应用标识、设备标识、配置文件以及密钥 #DF...
  4. Windows性能分析器概述(三)
  5. Unity3D-光照系统
  6. 印度软件开发人员_我如何辍学并在19岁时在印度找到了一份开发人员的工作
  7. 新网域名查询和注册API接口类 源码
  8. 2 打两拍verilog与Systemverilog编码
  9. 牛客网编程题07--提取不重复的整数
  10. vfp 界面_VFP之老树新花
  11. ios- uitextview的详细使用方法
  12. xmind试用模式会过期吗_汽车发动机机油「保质期」概念解析:机油真的会过期吗?...
  13. 虚拟服务器修改教程,【新挑战】十二职业虚拟机一键端图文架设修改教程
  14. 更改matlab快捷键 matlab 复制粘贴键不对
  15. 竞赛党关注!2021年五大学科竞赛考试时间,附985高校竞赛要求
  16. 博士申请 | 港中深韩晓光课题组招收与华为中央媒体院联合培养博士生
  17. vue3获取当前日期和时间
  18. VMware vSphere 7 vCenter 7 ESXi 7 正式版下载地址
  19. MCE公司:黄芩苷通过激活肝脏 CPT1 酶改善饮食诱导的肥胖和脂肪肝病变
  20. box2d 碰撞检测_Box2d新系列 第四章 碰撞模块

热门文章

  1. 手把手教你Android标准App的四大自动化测试法宝
  2. Mybatis-Plus+SpringBoot框架详解
  3. 2020年《财富》世界500强企业分析报告
  4. [SDOI2017]苹果树
  5. 网络架构系列1--TCP/IP详解
  6. 62、63 不同路径
  7. 使用selenium,xpath,线程池爬取斗鱼主播信息
  8. instanceof 和isInstance
  9. 无穷小微积分不减反增,何故?
  10. matlab计算auc,ROC和AUC介绍以及如何计算AUC