📄 contour.c
字号:
h[m] = f(d,(i+im[m-1]),(j+jm[m-1])) - f(z,k,VCT);
xh[m]= f(x,i+im[m-1],VCT);
yh[m]= f(y,j+jm[m-1],VCT);
}
if ( m==0 )
{
h[0] = (h[1]+h[2]+h[3]+h[4])/4;
xh[0] = ( f(x,i,VCT) + f(x,i+1,VCT) )/2;
yh[0] = ( f(y,j,VCT) + f(y,j+1,VCT) )/2;
}
if ( h[m] > 0 ) ish[m]= 2;
else if ( h[m] < 0 ) ish[m]= 0;
else ish[m]= 1;
} /* end m loop */
for (m = 1; m <= 4; m++)
{
m1 =m;
m2 = 0;
m3 = m+1;
if (m3 == 5) m3 = 1;
caseval = castab [ish[m1]] [ish[m2]] [ish[m3]];
/* Scan each triangle in grid square */
switch (caseval)
{
case 0 : break; /* No intersection */
case 1 : x1 =xh[m1]; /* Line between vertices m1 and m2 */
y1=yh[m1];
x2=xh[m2];
y2=yh[m2];
break;
case 2 : x1 =xh[m2]; /* Line between vertices m2 and m3 */
y1=yh[m2];
x2=xh[m3];
y2=yh[m3];
break;
case 3 : x1 =xh[m3];/* Line between vertices m3 and m1 */
y1=yh[m3];
x2=xh[m1];
y2=yh[m1];
break;
case 4 : x1=xh[m1]; /* Line between vertices m1 and side m2-m3 */
y1=yh[m1];
x2=(h[m3]*xh[m2]-h[m2]*xh[m3])/(h[m3]-h[m2]);
y2=(h[m3]*yh[m2]-h[m2]*yh[m3])/(h[m3]-h[m2]);
break;
case 5 : x1=xh[m2]; /* Line between vertices m2 and side m3-m1 */
y1=yh[m2];
x2=(h[m1]*xh[m3]-h[m3]*xh[m1])/(h[m1]-h[m3]);
y2=(h[m1]*yh[m3]-h[m3]*yh[m1])/(h[m1]-h[m3]);
break;
case 6 : x1=xh[m3]; /* Line between vertices m3 and side m1-m2 */
y1=yh[m3];
x2=(h[m2]*xh[m1]-h[m1]*xh[m2])/(h[m2]-h[m1]);
y2=(h[m2]*yh[m1]-h[m1]*yh[m2])/(h[m2]-h[m1]);
break;
/* Line between sides m1-m2 & m2-m3 */
case 7 : x1 =(h[m2]*xh[m1]-h[m1]*xh[m2])/(h[m2]-h[m1]);
y1 =(h[m2]*yh[m1]-h[m1]*yh[m2])/(h[m2]-h[m1]);
x2 =(h[m3]*xh[m2]-h[m2]*xh[m3])/(h[m3]-h[m2]);
y2 =(h[m3]*yh[m2]-h[m2]*yh[m3])/(h[m3]-h[m2]);
break;
/* Line between sides m2-m3 & m3-m1 */
case 8 : x1 =(h[m3]*xh[m2]-h[m2]*xh[m3])/(h[m3]-h[m2]);
y1 =(h[m3]*yh[m2]-h[m2]*yh[m3])/(h[m3]-h[m2]);
x2 =(h[m1]*xh[m3]-h[m3]*xh[m1])/(h[m1]-h[m3]);
y2 =(h[m1]*yh[m3]-h[m3]*yh[m1])/(h[m1]-h[m3]);
break;
/* Line between sides m3-m1 & m1-m2 */
case 9 : x1 =(h[m1]*xh[m3]-h[m3]*xh[m1])/(h[m1]-h[m3]);
y1 =(h[m1]*yh[m3]-h[m3]*yh[m1])/(h[m1]-h[m3]);
x2 =(h[m2]*xh[m1]-h[m1]*xh[m2])/(h[m2]-h[m1]);
y2 =(h[m2]*yh[m1]-h[m1]*yh[m2])/(h[m2]-h[m1]);
break;
default : printf("The defined case for vertex %d, contour %d\n",m,k);
printf("grid %d,%d does not exist\n", k,i,j);
}
if (caseval!=0)
{
drawit(x1,y1,x2,y2,x,y,iub,jub);
}
} /* Loop m */
} /* if */
} /* Loop k */
}
/*============================================================================*/
void drawit (float x1, float y1, float x2, float y2,
struct fmat *x, struct fmat *y,int iub, int jub )
/*============================================================================*/
{
x1 = (NO_COLS-3)*x1/(f(x,iub,VCT))+1; /* Draw the selected */
y1 = (NO_ROWS-3)*y1/(f(y,jub,VCT))+1; /* line segment in */
x2 = (NO_COLS-3)*x2/(f(x,iub,VCT))+1; /* the frame buffer */
y2 = (NO_ROWS-3)*y2/(f(y,jub,VCT))+1;
dda(x1,y1,x2,y2,'+');
}
/*============================================================================*/
void set_graphics(void)
/*============================================================================*/
{
erase(); /* Clear the fuffer */
box(0,0,NO_COLS-1,NO_ROWS-1); /* Draw box in frame */
} /* buffer */
/*===========================================================================*/
void box(float x1,float y1,float x2,float y2 )
/*===========================================================================*/
{
xchk(x1);xchk(x2);ychk(y1);ychk(y2); /* Draw box with ASCII */
frame[x1][y1] ='*'; /* characters in */
dda(x1,y1+1, x1,y2-1,'|'); /* the graphic frame */
frame[x1][y2] ='*';
dda(x1+1,y2, x2-1,y2,'-');
frame[x2][y2] ='*';
dda(x2,y2-1, x2,y1+1,'|');
frame[x2][y1] ='*';
dda(x2-1,y1, x1+1,y1,'-');
}
/*===========================================================================*/
void dda (float x1,float y1,float x2,float y2,char symbol)
/*===========================================================================*/
{
float x,y,dx_step,dy_step; /* Draw a line in */
int steps,i,dx,dy; /* the bufffer */
dx=x2-x1; /* Calc deltas */
dy=y2-y1;
steps=max(abs(dx),abs(dy))+1; /* Calc no steps */
dx_step=(float)dx/steps; /* Step size */
dy_step=(float)dy/steps;
x=x1+.5; /* Offsets for rounding */
y=y1+.5;
for (i=0; i<steps; i++) { /* Set pixels */
frame[floor(x)][floor(y)]=symbol;
x+=dx_step;
y+=dy_step;
}
frame[floor(x)][floor(y)]=symbol;
/* Last pixel */
}
/*===========================================================================*/
void display (void)
/*===========================================================================*/
{
int x,y; /* Display the frame */
/* buffer on the std */
clrscr(); /* output device */
for (y=NO_ROWS-1; y>=0; y--) {
for (x=0; x<NO_COLS; x++) {
putch(frame[x][y]);
}
putch('\n');
putch('\r');
}
}
/*===========================================================================*/
void erase (void)
/*===========================================================================*/
{
int x,y;
/* Clear the frame */
for(y=NO_ROWS; y>0; y--) { /* buffer */
for (x=1; x<=NO_COLS; x++) {
frame[x][y]='\x20';
}
}
}
/*===========================================================================*/
void file_output (void)
/*===========================================================================*/
{
char ch,filename[24];
int x,y;
FILE *FN;
printf("ASCII file copy desired ? (Y/N) => ");ch=getche();
if (ch=='Y'||ch=='y') { /* Output the frame */
/* buffer to a text- */
clrscr(); /* file */
printf("Enter the output filename desired:");
scanf("%s",filename);
FN=fopen(filename,"w");
for (y=NO_ROWS-1; y>=0; y--) {
for (x=0; x<NO_COLS; x++) {
putc(frame[x][y],FN);
}
putc('\n',FN);
}
fclose(FN);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -