NX二次开发-UF_MODL_intersect_objects获取两个对象的交点

 1     NX9+VS2012
 2 
 3     #include <uf.h>
 4     #include <uf_curve.h>
 5     #include <uf_modl.h>
 6     #include <uf_ui.h>
 7 
 8 
 9     UF_initialize();
10 
11     //创建直线
12     UF_CURVE_line_t LineCoods1;
13     LineCoods1.start_point[0] = 0.0;
14     LineCoods1.start_point[1] = 0.0;
15     LineCoods1.start_point[2] = 20.0;
16     LineCoods1.end_point[0] = 100.0;
17     LineCoods1.end_point[1] = 100.0;
18     LineCoods1.end_point[2] = 100.0;
19     tag_t Line1Tag = NULL_TAG;
20     UF_CURVE_create_line(&LineCoods1, &Line1Tag);
21 
22     UF_CURVE_line_t LineCoods2;
23     LineCoods2.start_point[0] = 50.0;
24     LineCoods2.start_point[1] = 50.0;
25     LineCoods2.start_point[2] = 0.0;
26     LineCoods2.end_point[0] = -50.0;
27     LineCoods2.end_point[1] = -50.0;
28     LineCoods2.end_point[2] = 100.0;
29     tag_t Line2Tag = NULL_TAG;
30     UF_CURVE_create_line(&LineCoods2, &Line2Tag);
31 
32     int IntersectionsNum;
33     UF_MODL_intersect_info_p_t * Intersections;
34     UF_MODL_intersect_objects(Line1Tag, Line2Tag, 0.01, &IntersectionsNum, &Intersections);//输入两个对象tag,找交点
35 
36     double IntersectionsPoint[3];//交点坐标
37     for (int i = 0; i < IntersectionsNum; i++)
38     {
39         int type = Intersections[i]->intersect_type;
40         if (type == UF_MODL_INTERSECT_POINT)
41         {
42             IntersectionsPoint[0] = Intersections[i]->intersect.point.coords[0];
43             IntersectionsPoint[1] = Intersections[i]->intersect.point.coords[1];
44             IntersectionsPoint[2] = Intersections[i]->intersect.point.coords[2];
45         }
46     }
47 
48 
49     //打印
50     char msg[256];
51     sprintf_s(msg, "X坐标:%f
Y坐标:%f
Z坐标:%f
", IntersectionsPoint[0], IntersectionsPoint[1], IntersectionsPoint[2]);
52     UF_UI_open_listing_window();
53     UF_UI_write_listing_window(msg);
54 
55     //释放
56     UF_free(Intersections);
57 
58     UF_terminate();

原文地址:https://www.cnblogs.com/nxopen2018/p/10975804.html