判断面是否相切,相切面。
用到的函数:
UF_MODL_ask_minimum_dist 获取两个对象之间的最短距离,以及点坐标 UF_MODL_ask_face_parm 给定一个参考点,返回曲面上的面参数(u,v),以及点。 UF_MODL_ask_face_props 输入面、面的uv参数。输出此位置的面法线
源码:
bool bool_is_Tangent(tag_t tagFace1, tag_t tagFace2); extern DllExport void ufsta(char *param, int *returnCode, int rlen) { UF_initialize(); tag_t tag_Face1 = 46607; tag_t tag_Face2 = 47338; if (bool_is_Tangent(tag_Face1, tag_Face2)) { uc1601("相切", 1); } else { uc1601("不相切", 1); } UF_terminate(); } extern int ufusr_ask_unload(void) { return (UF_UNLOAD_IMMEDIATELY); } bool bool_is_Tangent(tag_t tagFace1, tag_t tagFace2) { double guess1[3] = { 0.0,0.0,0.0 }; double guess2[3] = { 0.0,0.0,0.0 }; double min_dist = 0.0; double pt_on_ent1[3] = { 0.0,0.0,0.0 }; double pt_on_ent2[3] = { 0.0,0.0,0.0 }; UF_MODL_ask_minimum_dist(tagFace1, tagFace2, 0, guess1, 0, guess2, &min_dist, pt_on_ent1, pt_on_ent2); if (min_dist > 0.01) { return false; } double param1[2] = { 0.0,0.0 };//面部参数(u,v) double param2[2] = { 0.0,0.0 };//面部参数(u,v) UF_MODL_ask_face_parm(tagFace1, pt_on_ent1, param1, pt_on_ent1); UF_MODL_ask_face_parm(tagFace2, pt_on_ent2, param2, pt_on_ent2); double u1[3] = { 0.0,0.0,0.0 }; double v1[3] = { 0.0,0.0,0.0 }; double u2[3] = { 0.0,0.0,0.0 }; double v2[3] = { 0.0,0.0,0.0 }; double fx_1[3] = { 0.0,0.0,0.0 };//面法线 double fx_2[3] = { 0.0,0.0,0.0 };//面法线 double radii[2] = { 0.0,0.0 }; //输入面,面的uv参数。输出此位置的面法线 UF_MODL_ask_face_props(tagFace1, param1, pt_on_ent1, u1, v1, u2, v2, fx_1, radii); UF_MODL_ask_face_props(tagFace2, param2, pt_on_ent2, u2, v2, u2, v2, fx_2, radii); double dTolerance = 0.01; //相切公差 if (fabs(fabs(fx_1[0]) - fabs(fx_2[0])) < dTolerance && fabs(fabs(fx_1[1]) - fabs(fx_2[1])) < dTolerance && fabs(fabs(fx_1[2]) - fabs(fx_2[2])) < dTolerance) { return true; } else { return false; } }
效果: