📄 tmac2.bak
字号:
else{
e_x = b_x;
e_y = atof(&(buf[b_p+1]));
e_y -= o_y;
}
if (fabs(e_x-b_x) + fabs(e_y-b_y) < 0.0001)
return -1;
oldx = curx = b_x;
oldy = cury = b_y;
if (fabs(e_x-b_x) > fabs(e_y-b_y)){
len = sqrt((e_x-b_x)*(e_x-b_x)+(e_y-b_y)*(e_y-b_y));
if (len*xsteps > 2*x_len_to_acc){
s = (len*xsteps - 2*x_len_to_acc) -
(int)((len*xsteps - 2*x_len_to_acc)/vmax)*vmax;
s2 = s1 = s/2;
for (i=0;i<x_times;i++){
strcpy(buf1,"P");
if (s1 > 0){
if (s1 > 1){
xx = (i+1)*x_once_max_a_pulses + 2;
s1 -= 2;
}
else{
xx = (i+1)*x_once_max_a_pulses + 1;
s1 --;
}
}
else
xx = (i+1)*x_once_max_a_pulses;
yy = xx*fabs(e_y-b_y)/fabs(e_x-b_x);
xx1 = xx;
yy1 = yy;
xx = xx*xx1/sqrt(xx1*xx1+yy1*yy1);
yy = yy*xx1/sqrt(xx1*xx1+yy1*yy1);
if (e_x < b_x)
xx = -xx;
if (e_y < b_y)
yy = -yy;
curx = oldx + xx/xsteps;
cury = oldy + yy/ysteps;
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else{
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
oldxx = x;
oldyy = y;
x_count += x;
y_count += y;
}
times = (int)((len*xsteps - 2*x_len_to_acc)/vmax);
for (i=0;i<times;i++){
strcpy(buf1,"P");
xx = vmax*fabs(e_x-b_x)/sqrt((e_x-b_x)*(e_x-b_x)+(e_y-b_y)*(e_y-b_y));
yy = xx*fabs(e_y-b_y)/fabs(e_x-b_x);
// xx = vmax;
// yy = xx*fabs(e_y-b_y)/sqrt((e_x-b_x)*(e_x-b_x)+(e_y-b_y)*(e_y-b_y));
/*
xx1 = xx;
yy1 = yy;
xx = xx*xx1/sqrt(xx1*xx1+yy1*yy1);
yy = yy*yy1/sqrt(xx1*xx1+yy1*yy1);
*/
if (e_x < b_x)
xx = -xx;
if (e_y < b_y)
yy = -yy;
curx = oldx + xx/xsteps;
cury = oldy + yy/ysteps;
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else{
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
oldxx = x;
oldyy = y;
x_count += x;
y_count += y;
}
x_count += x;
y_count += y;
for (i=0;i<x_times;i++){
strcpy(buf1,"P");
if (s2 > 0){
if (s2 > 1){
xx = (x_times - i)*x_once_max_a_pulses + 2;
s2 -= 2;
}
else{
xx = (x_times - i)*x_once_max_a_pulses + 1;
s2 --;
}
}
else
xx = (x_times - i)*x_once_max_a_pulses;
yy = xx*fabs(e_y-b_y)/fabs(e_x-b_x);
xx1 = xx;
yy1 = yy;
xx = xx*xx1/sqrt(xx1*xx1+yy1*yy1);
yy = yy*xx1/sqrt(xx1*xx1+yy1*yy1);
if (e_x < b_x)
xx = -xx;
if (e_y < b_y)
yy = -yy;
if (i != x_times-1){
curx = oldx + xx/xsteps;
cury = oldy + yy/ysteps;
}
else{
curx = e_x;
cury = e_y;
}
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else{
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
oldxx = x;
oldyy = y;
x_count += x;
y_count += y;
}
}
else{
/*
len /= 2;
times = 0;
ll = 0;
while (ll < len){
times ++;
xx = times*x_once_max_a_pulses/xsteps;
yy = xx*fabs(e_y-b_y)/fabs(e_x-b_x);
xx1 = xx;
yy1 = yy;
xx = xx*xx1/sqrt(xx1*xx1+yy1*yy1);
yy = yy*xx1/sqrt(xx1*xx1+yy1*yy1);
ll += sqrt(xx*xx + yy*yy);
}
ll -= sqrt(xx*xx + yy*yy);
times --;
s1 = s2 = (len - ll)*xsteps;
for (i=0;i<times;i++){
strcpy(buf1,"P");
if (s1 > 0){
if (s1 > 1){
xx = (i+1)*x_once_max_a_pulses + 2;
s1 -= 2;
}
else{
xx = (i+1)*x_once_max_a_pulses + 1;
s1 --;
}
}
else
xx = (i+1)*x_once_max_a_pulses;
yy = xx*fabs(e_y-b_y)/fabs(e_x-b_x);
xx1 = xx;
yy1 = yy;
xx = xx*xx1/sqrt(xx1*xx1+yy1*yy1);
yy = yy*xx1/sqrt(xx1*xx1+yy1*yy1);
if (e_x < b_x)
xx = -xx;
if (e_y < b_y)
yy = -yy;
curx = oldx + xx/xsteps;
cury = oldy + yy/ysteps;
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else{
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
oldxx = x;
oldyy = y;
x_count += x;
y_count += y;
}
for (i=0;i<times;i++){
strcpy(buf1,"P");
if (s2 > 0){
if (s2 > 1){
xx = (times - i)*x_once_max_a_pulses + 2;
s2 -= 2;
}
else{
xx = (times - i)*x_once_max_a_pulses + 1;
s2 --;
}
}
else
xx = (times - i)*x_once_max_a_pulses;
yy = xx*fabs(e_y-b_y)/fabs(e_x-b_x);
xx1 = xx;
yy1 = yy;
xx = xx*xx1/sqrt(xx1*xx1+yy1*yy1);
yy = yy*xx1/sqrt(xx1*xx1+yy1*yy1);
if (e_x < b_x)
xx = -xx;
if (e_y < b_y)
yy = -yy;
if (i != times-1){
curx = oldx + xx/xsteps;
cury = oldy + yy/ysteps;
}
else{
curx = e_x;
cury = e_y;
}
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else{
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
oldxx = x;
oldyy = y;
x_count += x;
y_count += y;
}
*/
}
}
else{
len = sqrt((e_y-b_y)*(e_y-b_y)+(e_x-b_x)*(e_x-b_x));
if (len*ysteps > 2*y_len_to_acc){
s = (len*ysteps - 2*y_len_to_acc) -
(int)((len*ysteps - 2*y_len_to_acc)/vmax)*vmax;
s2 = s1 = s/2;
for (i=0;i<y_times;i++){
strcpy(buf1,"P");
if (s1 > 0){
if (s1 > 1){
yy = (i+1)*y_once_max_a_pulses + 2;
s1 -= 2;
}
else{
yy = (i+1)*y_once_max_a_pulses + 1;
s1 --;
}
}
else
yy = (i+1)*y_once_max_a_pulses;
xx = yy*fabs(e_x-b_x)/fabs(e_y-b_y);
xx1 = xx;
yy1 = yy;
xx = xx*yy1/sqrt(xx1*xx1+yy1*yy1);
yy = yy*yy1/sqrt(xx1*xx1+yy1*yy1);
if (e_y < b_y)
yy = -yy;
if (e_x < b_x)
xx = -xx;
curx = oldx + xx/xsteps;
cury = oldy + yy/ysteps;
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
strcpy(buf1,"P");
itoa(x,buf2,10);
strcat(buf1,buf2);
itoa(y,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -