pythonocc进阶学习:投影projection
1.点 到 线,(直线,曲线)等上的投影
@staticmethod # 点到Lin的投影
def Project_Pnt_To_Lin(p: gp_Pnt, lin: gp_Lin):Edge = BRepBuilderAPI_MakeEdge(lin).Edge()curve = BRep_Tool.Curve(Edge)proPnt = GeomAPI_ProjectPointOnCurve(p, curve[0])NearestPoint = proPnt.NearestPoint()return NearestPoint
2.点 到面上的投影
@staticmethod # 点到Pln的投影
def project_point_on_plane(plane, point):pl = plane.Pln()aa, bb = projlib_Project(pl, point).Coord()point = plane.Value(aa, bb)return point
3.wire至shape上的投影:
参考:http://www.cppblog.com/eryar/archive/2016/08/16/214182.html
BRepProj_Projection

from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire, BRepBuilderAPI_Transform
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_ThruSections
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere
from OCC.Core.BRepProj import BRepProj_Projection
from OCC.Core.GC import GC_MakeArcOfCircle, GC_MakeSegment
from OCC.Core.TopoDS import topods
from OCC.Core.gp import gp_Pnt, gp_Trsf, gp_Dir,gp_OX
from OCC.Display.SimpleGui import init_displaydisplay, start_display, add_menu, add_function_to_menu = init_display()
sphere = BRepPrimAPI_MakeSphere(50).Shape()height = 70
width = 50
thickness = 30print("creating bottle")
# The points we'll use to create the profile of the bottle's body
aPnt1 = gp_Pnt(-width / 2.0, 0, 0)
aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0)
aPnt3 = gp_Pnt(0, -thickness / 2.0, 0)
aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0)
aPnt5 = gp_Pnt(width / 2.0, 0, 0)aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
aSegment2 = GC_MakeSegment(aPnt4, aPnt5)# Could also construct the line edges directly using the points instead of the resulting line
aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())# Create a wire out of the edges
aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())# Quick way to specify the X axis
xAxis = gp_OX()# Set up the mirror
aTrsf = gp_Trsf()
aTrsf.SetMirror(xAxis)# Apply the mirror transformation
aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf)# Get the mirrored shape back out of the transformation and convert back to a wire
aMirroredShape = aBRespTrsf.Shape()# A wire instead of a generic shape now
aMirroredWire = topods.Wire(aMirroredShape)# Combine the two constituent wires
mkWire = BRepBuilderAPI_MakeWire()
mkWire.Add(aWire.Wire())
mkWire.Add(aMirroredWire)
myWireProfile = mkWire.Wire()
display.DisplayShape(myWireProfile, color='yellow', transparency=0.9, update=True)res = BRepProj_Projection(myWireProfile, Box1, gp_Dir(0, 0, 1)) # api
wire1 = res.Current()
res.Next()
wire2 = res.Current()generator = BRepOffsetAPI_ThruSections(True)
generator.AddWire(myWireProfile)
generator.AddWire(wire2)
generator.Build()
display.DisplayShape(generator.Shape(), color='black', transparency=0.9, update=True)
display.DisplayShape(sphere, color='black', transparency=0.9, update=True)
# display.DisplayShape(res.Current(), color='black', transparency=0.9, update=True)
start_display()

4.空间curve至pln的投影
GeomProjLib–》函数描述
from OCC.Core import GeomProjLib
from OCC.Core.Geom import Geom_Planefrom OCC.Core.gp import gp_Pnt, gp_Trsf, gp_Dir,gp_OX
from OCC.Display.SimpleGui import init_display
from OCC.Core.GeomAPI import GeomAPI_Interpolate
from OCC.Core.TColgp import TColgp_HArray1OfPnt
from OCC.Core.gp import gp_Pntdisplay, start_display, add_menu, add_function_to_menu = init_display()print("creating Plane")
plane = Geom_Plane(gp_Pnt(0,0,0),gp_Dir(0,0,1))print("creating bspline")
points = []
points=TColgp_HArray1OfPnt(1,3)
p1=gp_Pnt(0,6,2)
p2=gp_Pnt(2,1,3)
p3=gp_Pnt(6,2,1)points.SetValue(1,p1)
points.SetValue(2,p2)
points.SetValue(3,p3)
interp=GeomAPI_Interpolate(points,False,0.0001)
interp.Perform()
curve=interp.Curve() #Geom_BsplineCurve# project
proj=GeomProjLib.geomprojlib.ProjectOnPlane(curve,plane, gp_Dir(0, 0, 1),True)# display original curve and projected curve
display.DisplayShape(curve,color='blue',update=True)
display.DisplayShape(proj, color='red', update=True)start_display()

相关文章:
pythonocc进阶学习:投影projection
1.点 到 线,(直线,曲线)等上的投影 staticmethod # 点到Lin的投影 def Project_Pnt_To_Lin(p: gp_Pnt, lin: gp_Lin):Edge BRepBuilderAPI_MakeEdge(lin).Edge()curve BRep_Tool.Curve(Edge)proPnt GeomAPI_ProjectPointOnCurve(p, curve[0])Neares…...
Scractch3.0_Arduino_ESP32_学习随记_显示网络天气(二)
这里写目录标题 目的器材程序联系我们 目的 通过C02获取网络天气。并在屏上显示 器材 硬件: 齐护机器人C02 购买地址 软件: scratch3.0 下载地址:官网下载 程序 使用的是公开免费的API,对请求间隔和次数有限制,如果连续获取可能会被封IPÿ…...
Mysql压力测试(sysbench)
目录 配置项目环境: 参考:采用sysbench压测mysql详解_dream21st的博客-CSDN博客 实验步骤: 1、安装sysbench工具 2、在master上创建用户和库,配置用户的权限可以使他可以访问库(Mysql的主从复制) 3、基…...
TBDS MPP参数列表
TBDS MPP参数列表 namesettingdescriptionapplication_namessqlSets the application name to be reported in statistics and logs.archive_cleanup_commandSets the shell command that will be executed at every restart point.archive_command(disabled)Sets the shell co…...
C# OpenCvSharp 读取rtsp流
效果 项目 代码 using OpenCvSharp; using OpenCvSharp.Extensions; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using Syste…...
每日后端面试5题 第七天
一、内连接和外连接查询有什么区别? 内连接只查询出两表的交集; 外连接会查询出某表的全部与两表的交集。 二、Nginx的作用 1.反向代理 前端把请求发送给nginx,再由nginx将请求发送给后端服务器。 2.负载均衡 提高访问速度;…...
计算机视觉的应用10-图片中的表格结构识别与提取实战
大家好,我是微学AI,今天给大家介绍一下计算机视觉的应用10-图片中的表格结构识别与提取实战,表格结构识别在信息处理领域中具有广泛应用,但由于表格的多样性和复杂性,以及难以准确解析的布局和格式,传统的方…...
P4178 Tree (点分治)
题目链接 一:我们考虑树上两点之间的路径有什么情况 1:经过根节点(即在根节点的两端) 2:不经过根节点(完全在一颗子树的一侧) 二:我们考虑这两种路径是否可以归为一类 1࿱…...
Kubernetes 二进制搭建
Kubernetes 二进制搭建 一、二进制搭建 Kubernetes v1.201.1 部署准备1.2 操作系统初始化配置1.3 部署 etcd 集群1.3.1 etcd 作为服务发现系统,有以下的特点1.3.2 准备签发证书环境1.3.3 在 master01 节点上操作1.3.4 生成证书 1.4 部署 docker引擎1.4.1 部署 Maste…...
QT QtXlsx安装使用
QtXlsx介绍 QtXlsx是一个可以读取和写入Excel文件的库。它不需要Microsoft Excel,可以在Qt5支持的任何平台上使用。 这里一定是需要QT5支持的。 须知安装QtXlsx时,需要下载perl 1.安装perl 这里选择官网下载安装即可。 官网地址:https://p…...
Java医院信息化HIS管理系统源码
HIS模板分为两种:病历模板和报表模板。模板管理是运营管理的核心组成部分,是基层卫生健康云中各医疗机构定制电子病历和报表的地方,各医疗机构可根据自身特点特色定制电子病历和报表,制作的电子病历及报表可直接在业务系统中使用。…...
【Uni-App】uview 开发多端应用,密码显示隐藏功能不生效问题
出现的问题: 使用uview组件u-input框密码绑定时会出现右侧密码显隐图标不显示的问题 思路: 1.看了下uview源码,发现这有一段注释,我们需要把源码修改一下,问题出在这里 这行代码修改为 :password"password || …...
人工智能算法-SVM, KNN
目录 SVM, KNN区别 一、KNN算法概述 算法的描述: 二、关于K的取值 K的取法: 三、关于距离的选取 Euclidean Distance 定义: 四、总结 SVM, KNN区别...
计算机网络—TCP
这里写目录标题 TCP头格式有哪些为什么需要TCP,TCP工作在哪什么是TCP什么是TCP连接如何确定一个TCP连接TCP和UDP的区别,以及场景TCP和UDP能共用一个端口?TCP的建立TCP三次握手过程为什么是三次握手、不是两次、四次why每次建立连接࿰…...
Oracle到DM实时数据同步实施方案
目录 1 项目概述 2 需求分析 3 实施操作 3.1 历史数据全量同步 3.2 增量数据实时同步 4 问题总结 4.1 字符型非空约束 4.2 字符型唯一索引尾部空格 1 项目概述 将Oracle 11g RAC生产环境数据同步到DM8分析环境,Oracle数据库大小1.5T,日增归档10…...
WebRTC | 音视频实时通信的本质
目录 一、音视频实时通信的两种指标 1. 实时通信延迟指标 2. 视频相关的基本概念 3. 音视频服务质量指标 二、解决实时通信的主要矛盾 1. 增加带宽 A. 提供更优质的接入服务 B. 保证云端网络的带宽和质量 C. 更合理的路由调度策略 2. 减少数据量 A. 采用更好的压缩算…...
ApiPost的使用
1. 设计接口 请求参数的介绍 Query:相当于get请求,写的参数在地址栏中可以看到 Body: 相当于 post请求,请求参数不在地址栏中显示。 请求表单类型,用form-data json文件类型,用row 2. 预期响应期望 设置完每一项点一下生成响应…...
6、CCS 配置工程头文件批量添加路径的方法
1、进入到图示的框框里 2、编辑好需要添加的路径,并按ctrl c 3、选中include paths(-I)框框里的最后一条路径 4、然后ctrl v,这样路径就复制到预定义路径里了...
Visual Studio配置PCL库
Visual Studio配置PCL库 Debug和Release配置新建项目配置属性表测试参考 Debug和Release Debug和Release的配置过程一模一样,唯一区别就在于最后一步插入的附加依赖项不同,因此下面以debug为例。 配置新建项目 1、新建一个C空项目,模式设置…...
数据分析 | 为什么Bagging算法的效果优于单个评估器
1. 回归问题如何降低方差 以随机森林为例,假设随机森林中含有n个弱评估器,由于子样本集的相似性以及使用的是同种模型,因此各模型有近似相等的方差和偏差,因此假设任意弱评估器上输出结果为,方差均为,则随机森林的输出…...
iOS 26 携众系统重磅更新,但“苹果智能”仍与国行无缘
美国西海岸的夏天,再次被苹果点燃。一年一度的全球开发者大会 WWDC25 如期而至,这不仅是开发者的盛宴,更是全球数亿苹果用户翘首以盼的科技春晚。今年,苹果依旧为我们带来了全家桶式的系统更新,包括 iOS 26、iPadOS 26…...
Spring Boot 实现流式响应(兼容 2.7.x)
在实际开发中,我们可能会遇到一些流式数据处理的场景,比如接收来自上游接口的 Server-Sent Events(SSE) 或 流式 JSON 内容,并将其原样中转给前端页面或客户端。这种情况下,传统的 RestTemplate 缓存机制会…...
Java 8 Stream API 入门到实践详解
一、告别 for 循环! 传统痛点: Java 8 之前,集合操作离不开冗长的 for 循环和匿名类。例如,过滤列表中的偶数: List<Integer> list Arrays.asList(1, 2, 3, 4, 5); List<Integer> evens new ArrayList…...
MFC内存泄露
1、泄露代码示例 void X::SetApplicationBtn() {CMFCRibbonApplicationButton* pBtn GetApplicationButton();// 获取 Ribbon Bar 指针// 创建自定义按钮CCustomRibbonAppButton* pCustomButton new CCustomRibbonAppButton();pCustomButton->SetImage(IDB_BITMAP_Jdp26)…...
【机器视觉】单目测距——运动结构恢复
ps:图是随便找的,为了凑个封面 前言 在前面对光流法进行进一步改进,希望将2D光流推广至3D场景流时,发现2D转3D过程中存在尺度歧义问题,需要补全摄像头拍摄图像中缺失的深度信息,否则解空间不收敛…...
376. Wiggle Subsequence
376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...
docker 部署发现spring.profiles.active 问题
报错: org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...
论文笔记——相干体技术在裂缝预测中的应用研究
目录 相关地震知识补充地震数据的认识地震几何属性 相干体算法定义基本原理第一代相干体技术:基于互相关的相干体技术(Correlation)第二代相干体技术:基于相似的相干体技术(Semblance)基于多道相似的相干体…...
嵌入式学习笔记DAY33(网络编程——TCP)
一、网络架构 C/S (client/server 客户端/服务器):由客户端和服务器端两个部分组成。客户端通常是用户使用的应用程序,负责提供用户界面和交互逻辑 ,接收用户输入,向服务器发送请求,并展示服务…...
基于IDIG-GAN的小样本电机轴承故障诊断
目录 🔍 核心问题 一、IDIG-GAN模型原理 1. 整体架构 2. 核心创新点 (1) 梯度归一化(Gradient Normalization) (2) 判别器梯度间隙正则化(Discriminator Gradient Gap Regularization) (3) 自注意力机制(Self-Attention) 3. 完整损失函数 二…...
