马上注册,结交更多同行朋友,交流,分享,学习。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本人刚开始接触UG开发,想要绘制一条螺旋线,程序编译通过,可到UG里运行之后,却没有生成任何曲线,请各位高手大侠们帮偶看看吧~~~
本人不胜感激!!!
static void do_my_Program(double PARA[])
{
int i;
double my_dLead = PARA[0]; // 螺距
double my_dRad = PARA[1]; // 半径
double my_dZhuanNumber = PARA[2]; // 圈数
// 放置位置
double luowen_orig[3];
luowen_orig[0] = PARA[3];
luowen_orig[1] = PARA[4];
luowen_orig[2] = PARA[5];
CString str[3];
for (i=0 ; i<3 ; i++)
{
str.Format("%f", PARA);
}
char *LEAD = (char*)(LPCTSTR)str[0]; // 螺距
char *RAD = (char*)(LPCTSTR)str[1]; // 半径
char *numbers = (char*)(LPCTSTR)str[2]; // 转数
double direction_cyl[3]; // 矢量方向
direction_cyl[0] = 0.0;
direction_cyl[1] = 0.0;
direction_cyl[2] = 1.0;
int rec;
int degree = 3; // 样条次数
int periodicity = 1; // 0:非周期样条 1:周期样条
int save_def_data = 1; // 1则和创建的样条曲线一起保持输入数据,否则不保持
tag_t spline_tag; // 创建的样条曲线指针——输出
double start_pt[3], end_pt[3];
// 起点坐标
for (i=0 ; i<3 ; i++)
{
start_pt = luowen_orig;
}
start_pt[0] += my_dRad;
// 终点坐标
double min_num, integer;
double tem_pt[3]; // 上端面中心点
for (i=0 ; i<3 ; i++)
{
tem_pt = luowen_orig;
}
tem_pt[2] += PARA[0]*PARA[2];
min_num = modf(my_dZhuanNumber, &integer);
get_another_point(tem_pt, my_dRad, min_num, end_pt);
// 中间控制点
int all_ctrlpt_numbers;
int tem_ctrlpt; // 一个导程的中间控制点数
get_ctrlpt_number(my_dRad, tem_ctrlpt);
all_ctrlpt_numbers = integer * tem_ctrlpt + (int)(360*min_num/(360/tem_ctrlpt)); // 中控点的总个数
double **ctrl_pts;
ctrl_pts =(double **)malloc((2+all_ctrlpt_numbers)*sizeof(double *));
for(i=0 ; i<(2+all_ctrlpt_numbers) ; i++)
{
ctrl_pts=(double *)malloc(sizeof(double)*3);
}
//double ctrl_pts[all_ctrlpt_numbers][3];
getData_ctrl_Pts(luowen_orig, 2+all_ctrlpt_numbers, my_dRad, my_dLead, ctrl_pts, start_pt, end_pt);
// 参数定义
int num_points = all_ctrlpt_numbers + 2; // (所有控制点的数目=起控点+中控点+终控点)point_data[]数组中点和参数的数目
//UF_CURVE_pt_slope_crvatr_t point_data[all_ctrlpt_numbers]; // 定义样条上的点和斜率控制的数组
UF_CURVE_pt_slope_crvatr_t *point_data;
point_data = (UF_CURVE_pt_slope_crvatr_t *)malloc(num_points*sizeof(UF_CURVE_pt_slope_crvatr_t));
double *slopeVecs;
slopeVecs = (double *)malloc(num_points*sizeof(double));
get_slope_point(luowen_orig, num_points, my_dRad, my_dLead, slopeVecs);
double *crvatrVecs;
crvatrVecs = (double *)malloc(num_points*sizeof(double));
get_crvatr_point(luowen_orig, num_points, my_dRad, my_dLead, crvatrVecs);
for (i= 0; i<num_points; i++)
{
point_data.point[0] = ctrl_pts[0];
point_data.point[1] = ctrl_pts[1];
point_data.point[2] = ctrl_pts[2];
point_data.slope_type = UF_CURVE_SLOPE_AUTO;
point_data.slope[0] = slopeVecs[3*i];
point_data.slope[1] = slopeVecs[3*i+1];
point_data.slope[2] = slopeVecs[3*i+2];
point_data.crvatr_type = UF_CURVE_CRVATR_NONE;
point_data.crvatr[0] = crvatrVecs[3*i];
point_data.crvatr[1] = crvatrVecs[3*i+1];
point_data.crvatr[2] = crvatrVecs[3*i+2];
}
// 节点
double *parameters; // 输入点参数
parameters = (double *)malloc((num_points + 4)*sizeof(double));
getData_node(degree, num_points, parameters);
rec = UF_CURVE_create_spline_thru_pts(degree, periodicity, num_points, point_data, parameters, save_def_data, &spline_tag);
for(i=0 ; i<all_ctrlpt_numbers ; i++)
{
free(ctrl_pts);
}
free(ctrl_pts);
free(point_data);
free(parameters);
free(slopeVecs);
free(crvatrVecs);
}
// 已知半径和圈数,求旋转后点的XY坐标
static void get_another_point(double pt[], double rad, double angle, double new_point[3])
{
double radian = angle * 2*PI;
new_point[0] = rad*cos(radian) + pt[0];
new_point[1] = rad*sin(radian) + pt[1];
new_point[2] = pt[2];
}
// 由螺旋线半径确定一个导程里的中间控制点数目
static void get_ctrlpt_number(double rad, int &ctrlpt_number)
{
if (rad>=1 && rad<15)
{
ctrlpt_number = 8;
}
else
{
if (rad>=15 && rad<205)
{
ctrlpt_number = 16;
}
else
{
if (rad>=205 && rad<3285)
{
ctrlpt_number = 32;
}
else
{
ctrlpt_number = 64;
}
}
}
}
// 由放置点、控点个数、半径、导程,确定各个中控点坐标
static void getData_ctrl_Pts(double org_pt[3], int pt_number, double rad, double lead, double **ctrl_pts, double stpoint[3], double edpoint[3])
{
double angle;
double tem_pt[3], tem_ctrlPt[3];
int i, j;
for (i=0 ; i<3 ; i++)
{
tem_pt = org_pt;
}
int tem_ctrlpt_num; // 一个导程中的控制点数
get_ctrlpt_number(rad, tem_ctrlpt_num);
double length_add_perPt = lead/tem_ctrlpt_num; // 每增加一个控制点,在Z方向上的增量
for (i=0 ; i<pt_number; i++)
{
if (i==0 || i==pt_number-1)
{
if (i==0)
{
for (j=0 ; j<3 ; j++)
{
ctrl_pts[j] = stpoint[j];
}
}
else
{
for (j=0 ; j<3 ; j++)
{
ctrl_pts[j] = edpoint[j];
}
}
}
else
{
tem_pt[2] += length_add_perPt;
angle = i/(double)tem_ctrlpt_num;
get_another_point(tem_pt, rad, angle, tem_ctrlPt);
for (j=0 ; j<3 ; j++)
{
ctrl_pts[j] = tem_ctrlPt[j];
}
}
}
}
// 由阶数和控制点数目,获得节点
static void getData_node(int degree, int ctrl_number, double *DATA_node_number)
{
// 总节点数
int node_number = ctrl_number + 8 - degree;
int i;
for (i=0 ; i<node_number ; i++)
{
if (i<4)
{
DATA_node_number = 0;
}
else
{
if (i<(ctrl_number+4-degree))
{
DATA_node_number = (ctrl_number-degree-3)/(double)(ctrl_number-degree+1);
}
else
{
DATA_node_number = 1;
}
}
}
}
// 获得曲线上一点的斜率
static void get_slope_point(double org_pt[3], int pt_number, double rad, double lead, double *slope_pts)
{
double angle;
double tem_pt[3], tem_ctrlPt[3];
double radian;
int i, j;
for (i=0 ; i<3 ; i++)
{
tem_pt = org_pt;
}
int tem_ctrlpt_num; // 一个导程中的控制点数
get_ctrlpt_number(rad, tem_ctrlpt_num);
double length_add_perPt = lead/tem_ctrlpt_num; // 每增加一个控制点,在Z方向上的增量
for (i=0 ; i<pt_number; i++)
{
tem_pt[2] = tem_pt[2] + i*length_add_perPt;
angle = i/(double)tem_ctrlpt_num;
radian = angle * 2 * PI;
tem_ctrlPt[0] = -rad*sin(radian);
tem_ctrlPt[1] = rad*cos(radian);
tem_ctrlPt[2] = lead/2/PI;
for (j=0 ; j<3 ; j++)
{
slope_pts[3*i+j] = tem_ctrlPt[j];
}
}
}
// 获得曲线上一点的曲率
static void get_crvatr_point(double org_pt[3], int pt_number, double rad, double lead, double *crvatrVecs)
{
double angle;
double tem_pt[3], tem_ctrlPt[3];
double radian;
int i, j;
for (i=0 ; i<3 ; i++)
{
tem_pt = org_pt;
}
int tem_ctrlpt_num; // 一个导程中的控制点数
get_ctrlpt_number(rad, tem_ctrlpt_num);
double length_add_perPt = lead/tem_ctrlpt_num; // 每增加一个控制点,在Z方向上的增量
for (i=0 ; i<pt_number; i++)
{
tem_pt[2] += i*length_add_perPt;
angle = i/(double)tem_ctrlpt_num;
// 转数转化成弧度
radian = angle * 2 * PI;
tem_ctrlPt[0] = -rad*cos(radian);
tem_ctrlPt[1] = -rad*sin(radian);
tem_ctrlPt[2] = 0;
for (j=0 ; j<3 ; j++)
{
crvatrVecs[3*i+j] = tem_ctrlPt[j];
}
}
}
[ 本帖最后由 MIRRO_LEE 于 2009-2-27 20:21 编辑 ] |