文章作者:里海
简介
将对象从一个坐标系移动到另一个坐标系
代码
将对象从一个坐标系移动到另一个坐标系
#include "me.hpp"
static void matrix_csys2csys(tag_t tagRefCsys, tag_t dest_csys, double mx[12])
{
tag_t tagCsysMx1 = NULL_TAG;
double orig1[3] = { 0.0 };
UF_CSYS_ask_csys_info(tagRefCsys, &tagCsysMx1, orig1);
double csys1[9] = { 0.0 };
UF_CSYS_ask_matrix_values(tagCsysMx1, csys1);
double tx1[12] = { 0.0 };
tx1[0] = csys1[0];
tx1[1] = csys1[1];
tx1[2] = csys1[2];
tx1[3] = 0;
tx1[4] = csys1[3];
tx1[5] = csys1[4];
tx1[6] = csys1[5];
tx1[7] = 0;
tx1[8] = csys1[6];
tx1[9] = csys1[7];
tx1[10] = csys1[8];
tx1[11] = 0;
double
tx2[12],
tx3[12],
tx4[12],
v[3];
int
ii;
tag_t
csys_mx;
/* set up to translate from reference csys back to absolute */
for (ii = 0; ii < 3; ii++) v[ii] = -orig1[ii];
uf5943(v, tx2);
/* combine this with the rotation matrix from the reference csys */
uf5942(tx2, tx1, tx3);
double orig2[3] = { 0.0 };
UF_CSYS_ask_csys_info(dest_csys, &csys_mx, orig2);
double csys2[9] = { 0.0 };
UF_CSYS_ask_matrix_values(csys_mx, csys2);
/* Invert the rotation from the destination matrix */
tx2[0] = csys2[0];
tx2[1] = csys2[3];
tx2[2] = csys2[6];
tx2[3] = 0;
tx2[4] = csys2[1];
tx2[5] = csys2[4];
tx2[6] = csys2[7];
tx2[7] = 0;
tx2[8] = csys2[2];
tx2[9] = csys2[5];
tx2[10] = csys2[8];
tx2[11] = 0;
/* set up to translate from abs to the destination csys */
uf5943(orig2, tx1);
/* combine this with the inverted rotation csys above */
uf5942(tx2, tx1, tx4);
/* and the one from the reference csys */
uf5942(tx3, tx4, mx);
}
int inputXYCreatCsys(double douXdir[3], double douYdir[3], double csys_origin[3], tag_t &tagTempCsys)
{
double matrix_values[9];
UF_MTX3_initialize(douXdir, douYdir, matrix_values);//获得坐标矩阵
tag_t matrix_id = 0;
UF_CSYS_create_matrix(matrix_values, &matrix_id);//创建3×3矩阵
UF_CSYS_create_temp_csys(csys_origin, matrix_id, &tagTempCsys);//创建一个临时的坐标系统
return 0;
}
extern DllExport void ufusr(char* param, int* returnCode, int rlen)
{
UF_initialize();
double from_origin[3] = { 633.108799192 ,-176.304288218,0.000000000 };
double from_x_axis[3] = { 0.906307787 ,0.422618262,0.000000000 };
double from_y_axis[3] = { -0.404151854 ,0.866706447 ,0.292371705 };
double to_origin[3] = { 672.507610236 ,-175.301528262,0.000000000 };
double to_x_axis[3] = { 0.934731106 ,-0.223714002,0.276097454 };
double to_y_axis[3] = { 0.180782054 ,0.968273221,0.172524837 };
tag_t tagTempCsys1;
tag_t tagTempCsys2;
inputXYCreatCsys(from_x_axis, from_y_axis, from_origin, tagTempCsys1);
inputXYCreatCsys(to_x_axis, to_y_axis, to_origin, tagTempCsys2);
double mtx[12];
matrix_csys2csys(tagTempCsys1, tagTempCsys2, mtx);
tag_t tagObj = NULL_TAG;
dialogSelectObject(tagObj);
int status = 0;
int objects = 1; //数量
int move = 2; // 1 :移动 2 :复制
int layer = -1; //0:最初层; -1: 工作层; 1 - 256 : 指定层
int trace_curves = 2; //轨迹状态, 1 开, 2 关
tag_t wsc_t2 = NULL_TAG; //变化后坐标tag
uf5947(mtx, &tagObj, &objects, &move, &layer, &trace_curves, &wsc_t2, NULL, &status);//第二个对象 为被移动的对象
UF_terminate();
}
extern int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}
C++语言在UG二次开发中的应用及综合分析
- C++ 是C语言的扩展,它既可以执行C语言的过程化程序设计,也可以进行以抽象数据类型为特点的基于对象的设计,以及面向对象的程序设计。C++ 在处理问题规模上具有很大的适应性。
- C++不仅具有计算机高效运行的实用性特征,并且致力于提升大规模程序的编程质量以及程序设计语言的问题描述能力。
在UG二次开发中,C++语言具有以下特点
- C++语言支持多种程序设计风格
- C++的许多特性以库的形式存在,保证了语言的简洁和开发运行的效率
- 与C语言相比,C++引入了面向对象的概念,使得UG二次开发的人机交互界面更加简洁
- 通过借助UG自带的2000多种API函数,结合高级语言C++以及编程软件Visual Studio,可以对UG进行二次开发
- 需要注意的是,市场上的Visual Studio和UG版本众多,并非所有版本都能兼容
程序设计过程通常包括以下步骤:
- 问题分析:对要解决的问题进行深入的分析,理解问题的具体需求和限制。
- 需求定义:明确程序的目标和功能,包括用户需求、系统需求等。
- 设计:根据需求进行设计,包括算法设计、数据结构设计、界面设计等。
- 编码:根据设计的结果,使用一种编程语言将程序代码实现出来。
- 测试:通过各种测试方法来确保程序的正确性,包括单元测试、集成测试、系统测试等。
- 维护:对程序进行修改和完善,以解决可能出现的问题或满足新的需求。
- 文档编写:编写程序文档,描述程序的功能、操作方法、注意事项等。