NX二次開發-UFUN CSYS坐標系轉換UF_CSYS_map_point


 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日


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM