首页 > 其他分享 >cadquery创建螺纹thread

cadquery创建螺纹thread

时间:2023-10-22 16:24:35浏览次数:28  
标签:profile thread cadquery base 螺纹 pitch cq

参考来源: https://github.com/CadQuery/cadquery/issues/407

import math import cadquery as cq def profile(base, pitch, h, extra=True): """
pitch 螺距 Creates a trapezoidal wire for the cross section of the thread. If the cross section only goes out to the major diameter, then it doesn't cut a cylinder for some reason. Set extra=True to extend the cross section beyond the major diameter, to be certain it clears the outer surface of the base cylinder. """ vertices = [ base + cq.Vector(-5 / 8 * h, 0, -pitch / 8) , base + cq.Vector(0, 0, -7 / 16 * pitch) ] if extra: vertices.extend([ base + cq.Vector(h, 0, -7 / 16 * pitch) , base + cq.Vector(h, 0, 7 / 16 * pitch) ]) vertices.extend([ base + cq.Vector(0, 0, 7 / 16 * pitch) , base + cq.Vector(-5 / 8 * h, 0, pitch / 8) ]) vertices.append(vertices[0]) return vertices def thread_solid(pitch=3.5, major_diam=30+1e-4, length=10, included_angle=60, offset=0): """ Makes a solid representing a metric thread. Can be unioned to a tube with ID == major_diam to make an internal thread, or cut from a cylinder with OD == major_diam for an external thread. If offset != 0, then the profile is offset before sweeping, which can be used to add clearance. """ h = pitch / (2 * math.tan(included_angle / 2 * math.pi / 180)) base = cq.Vector(major_diam / 2, 0, 0) vertices = profile(base, pitch, h) profile_wire = cq.Wire.makePolygon(vertices) if offset: profile_wire = profile_wire.offset2D(offset)[0] # offset2d returns a list, we need the one and only wire returned # make the helical path to sweep path = cq.Wire.makeHelix(pitch, length + 2 * pitch, major_diam / 2, center=cq.Vector(0, 0, -pitch)) thread = cq.Solid.sweep(profile_wire, [], path, isFrenet=True) print(thread.isValid()) return thread thread = thread_solid(length=20) screw = ( cq .Workplane(origin=(0, 0, -5)) # make sure the thread cutting tool extends below the screw .circle(30 / 2) .extrude(30) # make sure the thread cutting toold extends above the screw .cut(thread,clean=False) ) screw = ( screw .faces('<Z').workplane(offset=-10).split(False,True) .faces('<Z').workplane(offset=-10).split(True) )
  1. profile 函数:

    • profile 函数用于创建螺纹横截面的轮廓。它的参数包括 base(基准点),pitch(螺距),h(梯形的高度)和 extra(一个布尔值,控制是否扩展轮廓以确保清除基础圆柱体的外表面)。
    • 该函数计算并返回一个包含横截面轮廓顶点坐标的列表,这些顶点定义了梯形的形状。
  2. thread_solid 函数:

    • thread_solid 函数用于创建表示度量螺纹的实体。可以将这个实体与具有内径等于 major_diam 的管道进行合并,以创建内部螺纹,或者从具有外径等于 major_diam 的圆柱体中进行切割,以创建外部螺纹。offset 参数用于控制轮廓是否在扫描之前进行偏移以添加间隙。
    • 该函数使用 profile 函数创建螺纹的横截面轮廓,然后使用 cq.Wire.makeHelix 创建一个螺旋路径,最后使用 Solid.sweep 函数将横截面轮廓沿着螺旋路径进行扫描以创建螺纹实体。
  3. 在接下来的代码部分,螺纹实体被切割以创建一个螺纹工具。切割工具由一个圆柱体组成,用于在后续步骤中切割螺纹。

  4. 最后,使用 cq.Workplane 创建一个工作平面,该平面从螺纹工具的底部开始,然后在螺纹工具上创建一个圆形。接着,使用 extrude 创建一个立体图形,然后使用 cut 将这个立体图形切割螺纹,从而创建一个带有螺纹的螺栓。接着对螺栓进行分割操作以将其切成一定长度。

  

标签:profile,thread,cadquery,base,螺纹,pitch,cq
From: https://www.cnblogs.com/arwen-xu/p/17780586.html

相关文章

  • 探索Java中神奇的ThreadLocal:为什么它是多线程编程的重要工具?
    (文章目录)......
  • 创建线程的三种方式:继承Thread、Runnable 接口、Callable 接口
    当在Java中创建线程时,有以下3种方法:1.通过实现Runnable接口:这是Java中创建线程的推荐方式,因为它允许你分离线程的任务(run方法)与线程的执行。以下是创建线程的步骤:创建一个实现Runnable接口的类,该接口包含一个run方法,这个方法将定义线程要执行的任务。classMyRunnableimpl......
  • 石油管螺纹刀具,公司参加第十七届中国国际机床展览会(CIMT2021)
    成都工具研究所有限公司的前身是成都工具研究所,于1956年创建于北京,是原机械工业部的直属研究所,是我国机械工业的综合性工具科研机构。公司官网:http://www.ctri.com.cn/公司主要从事精密切削工具、精密测量仪器以及表面改性处理技术的技术研究、产品开发和应用服务。 4月12-17......
  • -lpthread 和 pthread 以及 链接库的顺序
    写cmake文件时,编译一直无法正确识别欲调用的库函数,明明-lmysqlclient已经加上了。原本内容:(至今仍未解决,恳请各位点拨一下)cmake_minimum_required(VERSION3.0)project(HLWebServer)#设置C++标准为C++11set(CMAKE_CXX_FLAGS"${CMAKE_CXX_FLAGS}-pthread-lmysqlclient......
  • 深入理解 Netty FastThreadLocal
    作者:vivo互联网服务器团队-JiangZhu本文以线上诡异问题为切入点,通过对比JDKThreadLocal和NettyFastThreadLocal实现逻辑以及优缺点,并深入解读源码,由浅入深理解NettyFastThreadLocal。一、前言最近在学习Netty相关的知识,在看到NettyFastThreadLocal章节中,回想起一起线......
  • Redission并发锁报错:IllegalMonitorStateException: attempt to unlock lock, not loc
    生产上突然出现一条报错j.l.IllegalMonitorStateException:attempttounlocklock,notlockedbycurrentthreadbynodeid:1411e030-3c44-48d7-9eb6-6030022ce681thread-id:111ato.r.RedissonBaseLock.lambda$unlockAsync$2(RedissonBaseLock.java:323)......
  • Thread.Sleep() 和 Thread.SpinWait()
    Thread.Sleep()和Thread.SpinWait() 前言:应用程序应该让线程等待而不是切换。 一:Thread.Sleep(1000);Thread.Sleep()方法:是强制放弃CPU的时间片,然后重新和其他线程一起参与CPU的竞争。 二:Thread.SpinWait(1000);Thread.SpinWait()方法:只是让CPU去执行一段没有用的代......
  • threads隐私问题
    threadsapp隐私问题虽然转移数据很方便,但是处理不当的话,后有一些隐私问题;忘了是从哪个帖子里面看到的了;欢迎关注公-众-号【TaonyDaily】、留言、评论,一起学习。Don’treinventthewheel,librarycodeistheretohelp.文章来源:刘俊涛的博客若有帮助到您,欢迎点......
  • 【Java 并发编程】ThreadLocal
    目录ThreadLocalThreadLocal实现线程隔离的原理ThreadLocal内存泄漏场景ThreadLocalThreadLocal是一个将在多线程中为每一个线程创建单独的变量副本的类;当使用ThreadLocal来维护变量时,ThreadLocal会为每个线程创建单独的变量副本,避免因多线程操作共享变量而导致的数据不......
  • 第9期ThreadX视频教程:自制个微秒分辨率任务调度实现方案(2023-10-11)
    视频教程汇总帖:https://www.armbbs.cn/forum.php?mod=viewthread&tid=110519 说明:1、一般应用,我们都会将任务RTOS系统时钟节拍(心跳)设置为1ms,但如果直接把RTOS的系统时钟节拍设置为1us,系统负担非常大,而且很多RTOS也做不到100MHz主频下,1us切换一次任务,导致RTOS没有时间处理应用......