1 NX9+VS2012
2
3 #include <uf.h>
4 #include <uf_curve.h>
5 #include <uf_csys.h>
6 #include <uf_mtx.h>
7
8
9 UF_initialize();
10
11 //创建向量方向
12 double Vec[3] = { 10.0, 23.5, 75.8 };
13
14 //3*3矩阵,输入Z向量,得到矩阵
15 double Mtx[9];
16 UF_MTX3_initialize_z(Vec, Mtx);
17
18 //创建矩阵
19 tag_t MatrixTag = NULL_TAG;
20 UF_CSYS_create_matrix(Mtx, &MatrixTag);
21
22 //创建临时坐标系
23 double P1[3] = { 0.0, 0.0, 0.0 };//直线起点
24 tag_t CsysTag = NULL_TAG;
25 UF_CSYS_create_temp_csys(P1, MatrixTag, &CsysTag);
26
27 //设置WCS
28 UF_CSYS_set_wcs(CsysTag);
29
30 //创建直线终点
31 double P2[3] = { P1[0], P1[1], P1[2] + 100 };
32
33 //从当前工作坐标系转换到绝对坐标系
34 int InputCsys = UF_CSYS_ROOT_WCS_COORDS;
35 int OutputCsys = UF_CSYS_ROOT_COORDS;
36 double OutputPoint[3];
37 UF_CSYS_map_point(InputCsys, P2, OutputCsys, OutputPoint);
38
39 //创建直线
40 UF_CURVE_line_t LineCoods;
41 LineCoods.start_point[0] = P1[0];
42 LineCoods.start_point[1] = P1[1];
43 LineCoods.start_point[2] = P1[2];
44 LineCoods.end_point[0] = OutputPoint[0];
45 LineCoods.end_point[1] = OutputPoint[1];
46 LineCoods.end_point[2] = OutputPoint[2];
47 tag_t LineTag = NULL_TAG;
48 UF_CURVE_create_line(&LineCoods, &LineTag);
49
50 UF_terminate();
Caesar卢尚宇
2019年11月7日
2020年6月21日补充
上面的那个例子,有点小问题。修改后如下
NX9+VS2012 #include <uf.h> #include <uf_csys.h> #include <uf_mtx.h> #include <uf_curve.h> UF_initialize(); //初始化3*3矩阵 double x_vec[3] = {1.0, 0.0, 0.0}; double y_vec[3] = {0.0, 1.0, 0.0}; double mtx[9]; UF_MTX3_initialize(x_vec, y_vec, mtx); //创建矩阵 tag_t MatrixTag = NULL_TAG; UF_CSYS_create_matrix(mtx, &MatrixTag); //创建坐标系 double csys_origin [3] = {10, 10, 10}; tag_t CsysTag = NULL_TAG; UF_CSYS_create_csys(csys_origin, MatrixTag, &CsysTag); double P1[3] = { 10, 10, 10}; //创建直线终点 double P2[3] = { P1[0]+ 100, P1[1], P1[2]}; //从绝对坐标系转换到当前工作坐标系 int InputCsys = UF_CSYS_ROOT_WCS_COORDS; int OutputCsys = UF_CSYS_WORK_COORDS; double OutputPoint1[3]; double OutputPoint2[3]; UF_CSYS_map_point(InputCsys, P1, OutputCsys, OutputPoint1); UF_CSYS_map_point(InputCsys, P2, OutputCsys, OutputPoint2); //创建直线 UF_CURVE_line_t LineCoods; LineCoods.start_point[0] = OutputPoint1[0]; LineCoods.start_point[1] = OutputPoint1[1]; LineCoods.start_point[2] = OutputPoint1[2]; LineCoods.end_point[0] = OutputPoint2[0]; LineCoods.end_point[1] = OutputPoint2[1]; LineCoods.end_point[2] = OutputPoint2[2]; tag_t LineTag = NULL_TAG; UF_CURVE_create_line(&LineCoods, &LineTag); UF_terminate(); Caesar卢尚宇 2020年6月21日