NX/UG二次开发—参数方程绘制曲线UF_MODL_create_spline

最近在刀路转曲线,发现这个函数创建参数曲线非常方便,只需要有参数方程,即可创建样条线。其次,螺旋线比样条线要卡一些。这个函数还可以根据nurbs刀路信息绘制刀路曲线。

NX/UG二次开发—参数方程绘制曲线UF_MODL_create_spline_第1张图片

官方案例,创建一个样条类型的螺旋线:

static void do_ugopen_api(void)
{
  char *diams[2] = {"0.5", "0.0"};

  int i;
  int k_fixup;
  int p_fixup;

  tag_t spline_id;
  uf_list_p_t tubelist, tubefeats;
  UF_FEATURE_SIGN create = UF_NULLSIGN;

  double knotseq[POLES+ORDER];
  double pole_array[POLES*4];
  double x,y,z,t,w = WEIGHT;
  double delta_u = 1.0/((double)(POLES-ORDER+1));

  for(i = 0; i < ORDER; i++) {
    knotseq[i] = 0.0;
  }
  for(i = POLES; i < POLES + ORDER; i++) {
    knotseq[i] = 1.0;
  }
  i = 0;
  t =0.0;
  while( i < POLES*4){
    x = R1*cos(t) + .001;
    y = R1*sin(t) + .001;
    z = R2 + (R2/PI)*t;
    t += ANG;
    pole_array[i++] = x;
    pole_array[i++] = y;
    pole_array[i++] = z;
    pole_array[i++] = w;
    printf("%f, %f, %f, %f, %d\n",pole_array[i-4],pole_array[i-3],pole_array[i-2],pole_array[i-1],i-4);
  }
  for(i = ORDER; i < POLES ; i++){
    knotseq[i] = (i-ORDER+1)*delta_u;
  }

  printf("\nDelta u is = %f\n",delta_u);
  printf("Knot Sequence Values:\n");

  for(i = 0; i < POLES + ORDER; i++) printf("%f\n",knotseq[i]);
  if(k_fixup == 1) printf("Knot sequence was fixed.\n");
  if(p_fixup == 1) printf("Pole array was fixed.\n");
  UF_CALL(UF_MODL_create_spline(POLES,ORDER,knotseq,pole_array,&spline_id,&k_fixup,&p_fixup));
  UF_CALL(UF_MODL_create_list(&tubelist));
  UF_CALL(UF_MODL_put_list_item(tubelist, spline_id));
  UF_CALL(UF_MODL_create_tube(tubelist, diams, create,&tubefeats));

}

你可能感兴趣的:(NX二次开发,参数方程曲线)