iCAx开思工具箱

标题: 向zzz版主大哥请教个曲线相交得交点的问题 [打印本页]

作者: rafaleb01    时间: 2008-4-8 14:22
标题: 向zzz版主大哥请教个曲线相交得交点的问题
ZZZ和各位版主,各位学长 很不好意思现在还因为这么简单的问题打扰大家,但小弟试了很多次了就是得不到结果, 在建立好的模型上做条截面线,然后哦求得2截面线的交点,截面线我做出来了 但交点始终得不到 ,请ZZZ大哥和其他各位学长帮我看看,感激不尽
void ufusr(char *param, int *retcode, int param_len)
{
  if (!UF_CALL(UF_initialize()))
  {
//////////////////////////////////////////////////////////获得当前叶object_id
  
  int             type1,subtype;
  tag_t           part_tag;
  tag_t           block_tag;
  tag_t           plane1_tag;
  
  part_tag=UF_PART_ask_display_part();

  block_tag=NULL_TAG;

  UF_OBJ_cycle_objs_in_part(part_tag,UF_solid_type,&block_tag);

  while (block_tag)
  {
          UF_OBJ_ask_type_and_subtype(block_tag,&type1,&subtype);
  if (subtype==UF_solid_body_subtype)
  {
          break;
  }
  UF_OBJ_cycle_objs_in_part(part_tag,UF_solid_type,&block_tag);
  }
////////////////第一条截面线
double  origin1_point[3];
double  pl1_normal[3];
  
  origin1_point[0] = 20.0;
  origin1_point[1] = 40.0;
  origin1_point[2] = 0;
  
  pl1_normal[0] = 0.0;
  pl1_normal[1] = 0.0;
  pl1_normal[2] = 1.0;


  
UF_MODL_create_plane(origin1_point, pl1_normal, &plane1_tag);

    tag_t  objects1[1];
        tag_t  planes1[100];

objects1[0]=block_tag;

  
   tag_t section_curves_feature1;
   UF_CURVE_section_general_data_t  general1_data;
    UF_CURVE_section_planes_data_t   planes1_data;


       
    planes1[0] = plane1_tag;
    general1_data.associate     = 1;
    general1_data.objects       = objects1;
    general1_data.num_objects   = 1;
    general1_data.grouping      = 0;
    general1_data.join_type     = 0;
    general1_data.tolerance     = 0.0245;

    planes1_data.planes         = planes1;
    planes1_data.num_planes     = 1;

UF_CURVE_section_from_planes (&general1_data, &planes1_data,
                   &section_curves_feature1);

double  origin2_point[3];
double  pl2_normal[3];
  
  origin2_point[0] = 20.0;
  origin2_point[1] = 0;
  origin2_point[2] = 40.0;
  
  pl2_normal[0] = 0.0;
  pl2_normal[1] = 1.0;
  pl2_normal[2] = 0.0;

//////////////////////第二截面线
  tag_t plane2_tag;
UF_MODL_create_plane(origin2_point, pl2_normal, &plane2_tag);

    tag_t  objects2[1];
        tag_t  planes2[100];

objects2[0]=block_tag;

  
   tag_t section_curves_feature2;
   UF_CURVE_section_general_data_t  general2_data;
   UF_CURVE_section_planes_data_t   planes2_data;


       
    planes2[0] = plane2_tag;
    general2_data.associate     = 1;
    general2_data.objects       = objects2;
    general2_data.num_objects   = 1;
    general2_data.grouping      = 0;
    general2_data.join_type     = 0;
    general2_data.tolerance     = 0.0245;

    planes2_data.planes         = planes2;
    planes2_data.num_planes     = 1;

UF_CURVE_section_from_planes (&general2_data, &planes2_data,
                   &section_curves_feature2);

////////////////////求交
  int num_intersects, type;
  UF_MODL_intersect_info_p_t *intersect_data;



double tol = 0.1;

UF_MODL_intersect_objects(section_curves_feature2,section_curves_feature1,
                                                  tol,&num_intersects,&intersect_data);
红色部分是不是有错误?
FILE *fp4;


   if((fp4=fopen("e:\\my_source\\line4.txt","w"))==NULL)
   {
             printf("could not open data file.");
             exit(0);
   }

int i;
  for(i = 0; i < num_intersects; i++)
  {
    type = (intersect_data)->intersect_type;

       
    switch(type)
    {
      case UF_MODL_INTERSECT_POINT:

        fprintf(fp4,"\nx,y,z coordinates are: (%f, %f, %f)\n",
               (intersect_data)->intersect.point.coords[0],
               (intersect_data)->intersect.point.coords[1],
               (intersect_data)->intersect.point.coords[2]);

        fprintf(fp4,"Object 1 UV parameters are: (%f, %f)\n",
               (intersect_data)->intersect.point.object_1_u_parm,
               (intersect_data)->intersect.point.object_1_v_parm);

        fprintf(fp4,"Object 2 UV parameters are: (%f, %f)\n",
               (intersect_data)->intersect.point.object_2_u_parm,
               (intersect_data)->intersect.point.object_2_v_parm);

        break;

      case UF_MODL_INTERSECT_COINCIDE:

        printf("\nCoincident curve tag is: %d\n",
               intersect_data->intersect.coincide.identifier);

        printf("Object 1 UV parameters are: (%f, %f)\n",
               intersect_data->intersect.coincide.object_1_first_parm,
               intersect_data->intersect.coincide.object_1_second_parm);

        printf("Object 2 UV parameters are: (%f, %f)\n",
               intersect_data->intersect.coincide.object_2_first_parm,
               intersect_data->intersect.coincide.object_2_second_parm);
        break;

      case UF_MODL_INTERSECT_CURVE:

        printf("\nThe curve identifier is: %d\n",
               (intersect_data)->intersect.curve.identifier);
        break;

      default:

        printf("\nSomething went wrong, we shouldn't be here!");
        break;
    }

   // Free each element of the array.
      UF_free(intersect_data);
  }

  if(num_intersects != 0)
  {
  //// Free the array.
    UF_free(intersect_data);
  }


    UF_CALL(UF_terminate());
  }
}

int ufusr_ask_unload(void)
{
  return (UF_UNLOAD_IMMEDIATELY);
}
作者: zzz    时间: 2008-4-9 22:47
feature和feature求交,NX不能做吧
作者: rafaleb01    时间: 2008-4-11 14:29
那怎么才能实现目的呢?
作者: zzz    时间: 2008-4-11 20:24
用UF_MODL_ask_feat_objects可以问出两个section特征中的曲线,然后用曲线求交点
作者: rafaleb01    时间: 2008-4-15 08:36
恩 谢谢版主  我去试试看
作者: rafaleb01    时间: 2008-4-15 09:37
zzz大哥 针对上面的球形 用您给的函数我做出来了
但针对另一个零件却做不出来
平面与体相交得出的 4条线中 我都试过了 都报和第一条曲线没有交点
作者: rafaleb01    时间: 2008-4-15 10:10
还有 UF_CURVE_ask_feature_curves  输出的为
  num_section_curves2 is  4
section_curves2 is  19069
section_curves2 is  19070
section_curves2 is  19067
section_curves2 is  19068
UF_MODL_ask_feat_objects 得到的是
eiids2——num is  4
eiids2 is  19070
eiids2 is  19068
eiids2 is  19069
eiids2 is  19067
这两个函数得到的值基本一致,是不是可以相互替换啊?
作者: rafaleb01    时间: 2008-4-15 10:28
eids is  1
eiids[0] is  19066
eiids2 is  4
eiids2[0] is  19008
eiids2[1] is  19070
eiids2[2] is  19071
eiids2[3] is  19069

UF_MODL_intersect_objects(eiids2[0],eiids[0],tol,&num_intersects1,&intersect_1data);
UF_MODL_intersect_objects(eiids2[1],eiids[0],tol,&num_intersects2,&intersect_2data);
UF_MODL_intersect_objects(eiids2[2],eiids[0],tol,&num_intersects3,&intersect_3data);
UF_MODL_intersect_objects(eiids2[3],eiids[0],tol,&num_intersects4,&intersect_4data);

num_intersects1 are: 0
num_intersects2 are: 0
num_intersects3 are: 0
num_intersects4 are: 0
怎么会没有交点呢??
作者: zzz    时间: 2008-4-15 11:13
先在NX里面试一下,能不能选到两条线的交点,如果可以,说明你的代码有问题,如果不行,就说明确实没有交点。
作者: rafaleb01    时间: 2008-4-15 11:14
试了几个 这个函数似乎不适合样条曲线和样条曲线相交就点
作者: zzz    时间: 2008-4-15 11:18
你给的tol是多少?
作者: zzz    时间: 2008-4-15 11:19
原帖由  于 2008-4-15 10:10 发表
还有 UF_CURVE_ask_feature_curves  输出的为
  num_section_curves2 is  4
section_curves2 is  19069
section_curves2 is  19070
section_curves2 is  19067
section_curves2 is  19068
UF_MODL_ask_ ...



可以
作者: rafaleb01    时间: 2008-4-15 11:25
原贴由发表:
先在NX里面试一下,能不能选到两条线的交点,如果可以,说明你的代码有问题,如果不行,就说明确实没有交点。

交互下 选择插入点,捕捉项选择交点 确实看到捕捉到了2条交点
代码对圆柱体和椭圆柱体 圆球都有用 就是对通过曲线组拉出来的体没有效果
作者: rafaleb01    时间: 2008-4-15 14:14
tol 试过.0001 .001 .01 1 10.0 好像都没有结果
作者: zzz    时间: 2008-4-15 14:33
原帖由  于 2008-4-15 10:28 发表
eids is  1
eiids is  19066
eiids2 is  4
eiids2 is  19008
eiids2 is  19070
eiids2 is  19071
eiids2 is  19069

UF_MODL_intersect_objects(eiids2,eiids,tol,&num_intersects1,&inter ...


你看一下自己的代码,在求交时第二个参数总是eiids[0], 如果eiids[0]位于头部的话,肯定是没有交点的。
作者: rafaleb01    时间: 2008-4-15 14:47
ZZZ 大哥真是太崇拜你了 是公差的问题 UF_CURVE_section_from_planes 处的截线公差 api帮助文档里给的过大 造成的
真是麻烦您了
再次感谢




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3