当前位置: 首页 > news >正文

【OCCT+ImGUI系列】012-Geom2d_AxisPlacement

在这里插入图片描述

Geom2d_AxisPlacement 教学笔记

一、类概述

在这里插入图片描述
Geom2d_AxisPlacement 表示二维几何空间中的一个坐标轴(轴系),由两部分组成:

  • gp_Pnt2d:原点(Location)
  • gp_Dir2d:单位方向向量(Direction)

它是 Geom2d_Geometry 的派生类,可用于表示局部坐标系、图形基准轴、草图中对齐约束等。

二、构造方法

构造方式说明
Geom2d_AxisPlacement(gp_Pnt2d P, gp_Dir2d V)使用原点和单位方向构造坐标轴
Geom2d_AxisPlacement(gp_Ax2d A)gp_Ax2d 转换构造

示例:

Handle(Geom2d_AxisPlacement) axis = new Geom2d_AxisPlacement(gp_Pnt2d(0,0), gp_Dir2d(1,0));

三、常用方法解析

原点与方向操作
方法功能
SetLocation(const gp_Pnt2d& P)设置新原点
SetDirection(const gp_Dir2d& V)设置新方向(自动归一化)
Location()获取当前原点
Direction()获取当前方向
方向翻转
方法功能
Reverse()原地翻转方向向量
Reversed()返回一个反向的新副本(不修改原对象)
坐标轴整体操作
方法功能
SetAxis(const gp_Ax2d& A)设置完整坐标轴信息
Ax2d()返回对应的 gp_Ax2d 对象
Angle(const Handle<Geom2d_AxisPlacement>& Other)计算两个坐标轴方向夹角(单位:弧度,范围 -π 到 π)
Copy()克隆自身副本
Transform(const gp_Trsf2d& T)应用 2D 仿射变换(平移、旋转、镜像等)


四、代码片段示例

1. 设置位置

请添加图片描述

  // 单独设置 X 或 Yif (ImGui::SliderFloat("Set X", &coord[0], -100.0f, 100.0f)) {point2d->SetX(coord[0]);UpdatePoint(context);}if (ImGui::SliderFloat("Set Y", &coord[1], -100.0f, 100.0f)) {point2d->SetY(coord[1]);UpdatePoint(context);}
2. 利用Transform旋转

在这里插入图片描述

    void ApplyRotation(const Handle(AIS_InteractiveContext)& context) {gp_Trsf2d trsf;trsf.SetRotation(gp_Pnt2d(0, 0), rotateAngle * M_PI / 180.0);point2d->Transform(trsf);coord[0] = static_cast<float>(point2d->X());coord[1] = static_cast<float>(point2d->Y());UpdatePoint(context);}

五、总结

特点说明
轻量只包含点和方向向量
操作灵活支持方向翻转、复制、变换、方向角计算等
工程适用性强常用于草图系统、路径定义、投影方向设定等场景

六、代码

#pragma once#include "pch.h"
#include <Geom2d_CartesianPoint.hxx>
#include <Geom2d_Transformation.hxx>
#include <gp_Trsf2d.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <AIS_Shape.hxx>
#include "BaseScene.h"
#include "VisSceneComponents.h"
#include "TutorialWindow.h"class Geom2d012 : public BaseScene, public VisSceneComponents, public TutorialWindow {
public:Geom2d012() { openTutorialWindow(); }void displayScene(const Handle(V3d_View)& view, const Handle(AIS_InteractiveContext)& context) override {if (!bIsSceneInit) {sceneInit(view, context);bIsSceneInit = true;}renderTutorialWindow(context);}void customInitTutorialWindow(const Handle(AIS_InteractiveContext)& context) override {}void sceneInit(const Handle(V3d_View)&, const Handle(AIS_InteractiveContext)& context) override {// 初始化一个二维点point2d = new Geom2d_CartesianPoint(0.0, 0.0);VisualizePoint(context);}void renderTutorialContent(const Handle(AIS_InteractiveContext)& context) override {ImGui::Text("Geom2d_CartesianPoint Controls");// 单独设置 X 或 Yif (ImGui::SliderFloat("Set X", &coord[0], -100.0f, 100.0f)) {point2d->SetX(coord[0]);UpdatePoint(context);}if (ImGui::SliderFloat("Set Y", &coord[1], -100.0f, 100.0f)) {point2d->SetY(coord[1]);UpdatePoint(context);}ImGui::Separator();ImGui::Text("Transformation:");if (ImGui::SliderFloat("Rotate Angle (deg)", &rotateAngle, 0.0f, 360.0f)) {}if (ImGui::Button("Apply Rotation")) {ApplyRotation(context);}if (ImGui::Button("Reset Point")) {point2d->SetCoord(0.0, 0.0);coord[0] = 0.0f;coord[1] = 0.0f;UpdatePoint(context);}ImGui::Separator();ImGui::Text("Current Coordinates:");double x = point2d->X();double y = point2d->Y();ImGui::Text("X: %.2f, Y: %.2f", x, y);}private:Handle(Geom2d_CartesianPoint) point2d;Handle(AIS_Shape) pointAIS;float coord[2] = { 0.0f, 0.0f };float rotateAngle = 45.0f;void VisualizePoint(const Handle(AIS_InteractiveContext)& context) {gp_Pnt p3d(point2d->X(), point2d->Y(), 0.0);TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(p3d);pointAIS = new AIS_Shape(vertex);pointAIS->SetColor(Quantity_NOC_RED);context->Display(pointAIS, Standard_False);}void UpdatePoint(const Handle(AIS_InteractiveContext)& context) {gp_Pnt p3d(point2d->X(), point2d->Y(), 0.0);TopoDS_Vertex vertex = BRepBuilderAPI_MakeVertex(p3d);pointAIS->SetShape(vertex);context->Redisplay(pointAIS, Standard_False);}void ApplyRotation(const Handle(AIS_InteractiveContext)& context) {gp_Trsf2d trsf;trsf.SetRotation(gp_Pnt2d(0, 0), rotateAngle * M_PI / 180.0);point2d->Transform(trsf);coord[0] = static_cast<float>(point2d->X());coord[1] = static_cast<float>(point2d->Y());UpdatePoint(context);}
};

文章转载自:

http://6NzdX1De.ymmjx.cn
http://5SqsO2Qz.ymmjx.cn
http://LvLku4nM.ymmjx.cn
http://V7tgUFIE.ymmjx.cn
http://yHPVnHZA.ymmjx.cn
http://F6FZCJZG.ymmjx.cn
http://1OHkGY9N.ymmjx.cn
http://2obVgsPp.ymmjx.cn
http://khWHNhIq.ymmjx.cn
http://YC1XpjQJ.ymmjx.cn
http://tUPOhlYV.ymmjx.cn
http://x9Haxl2A.ymmjx.cn
http://H8k7THLx.ymmjx.cn
http://FuKqWTFI.ymmjx.cn
http://t5g2VZyq.ymmjx.cn
http://5Ep4AUHy.ymmjx.cn
http://zhLPEZrq.ymmjx.cn
http://YRZY8wUY.ymmjx.cn
http://9xbMwkkf.ymmjx.cn
http://DCp3b6AD.ymmjx.cn
http://83DrWMry.ymmjx.cn
http://Y5z0DmgC.ymmjx.cn
http://MvhkAlr1.ymmjx.cn
http://1r8f96IW.ymmjx.cn
http://ycxDQVsx.ymmjx.cn
http://JkJbPkjP.ymmjx.cn
http://MvtcNLIf.ymmjx.cn
http://2HymhNMN.ymmjx.cn
http://T09oOpi8.ymmjx.cn
http://NxHj3CG8.ymmjx.cn
http://www.dtcms.com/a/229613.html

相关文章:

  • 大模型:从基座构建到应用落地--预训练与后训练及个人解析-2025.6
  • CentOS Stream 8 Unit network.service not found
  • java类的生命周期
  • 【请关注】VC内存泄露的排除及处理
  • 基于wifi的室内定位算法设计与实现
  • 双周报Vol.73:移除使用方法实现 trait 、新增了 “错误多态” 功能、.语法支持使用 _ 的匿名函数...
  • 系统思考:短期利益与长期系统影响
  • vue实现点击单选或者多选模式
  • 力扣刷题 -- 225. 用队列实现栈
  • Matplotlib + Seaborn绘图类型清单
  • Java对象比较与排序的常见错误及解决方案
  • Unity异常上报飞书工具
  • ADI硬件笔试面试题型解析下
  • 【macbook】触控板手势
  • 词语翻译的三步法与背后的语言学思维
  • RPG20.创建敌人的初始能力和加载武器
  • MYSQL索引详解及索引优化、分析
  • 乐播视频v4.0.0纯净版体验:高清流畅的视听盛宴
  • C++ TCP传输心跳信息
  • 线性动态规划
  • Java面试八股--07-项目篇
  • AI“实体化”革命:具身智能如何重构体育、工业与未来生活
  • 数据库包括哪些?关系型数据库是什么意思?
  • “刹车思维”:慢,是为了更快
  • 什么是链游,链游系统开发价格以及方案
  • ESOP股权管理平台完整解决方案
  • 北京大学肖臻老师《区块链技术与应用》公开课:07-BTC-挖矿难度
  • superior哥AI系列第6期:Transformer注意力机制:AI界的“注意力革命“
  • 三、Sqoop 全量导入核心命令
  • 【摘录】显示屏购买要注意的参数