comb.c

来自「是Computational Geometry in C中的原程序」· C语言 代码 · 共 51 行

C
51
字号
/*This code is associated with "Computational Geometry in C" (Second Edition),Chapter 1.  It generates a comb polygon suitable for input totri.cInput: nOutput: n vertex coordinates for a comb polygon, in ccw orderCompile: gcc -o cone cone.cWritten by Joseph O'Rourke, with contributions by Min Xu.Last modified: October 1998Questions to orourke@cs.smith.edu.--------------------------------------------------------------------This code is Copyright 1997 by Joseph O'Rourke.  It may be freelyredistributed in its entirety provided that this copyright notice isnot removed.--------------------------------------------------------------------*/#include <stdio.h>#define	X	0#define	Y	1#define DIM     2               /* Dimension of points */typedef int     tPointi[DIM];   /* type integer point */#define PMAX    10000           /* Max # of pts in polygon */   typedef tPointi tPolygoni[PMAX];/* type integer polygon */main(){  tPolygoni P;  int i, j, n;  printf("n="); scanf("%d",&n);  for ( i = 0; i < n/2; i++ ) {    P[2*i][X] = n-2 - (2*i);    P[2*i][Y] = 0;    P[2*i+1][X] = n-2 - (2*i + 1);    P[2*i+1][Y] = 10;  }    P[n-1][X] = (n-2) / 2;  P[n-1][Y] = -2;  printf("%d\n", n);  for ( i = 0; i< n; i++)    printf("%d %d\n", P[i][X], P[i][Y]);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?