#define LEN sizeof(struct node)#include <math.h>#include<stdio.h>#include<graphics.h> struct node { int dx,dy; struct node *next; };struct node *creat(){ struct node *h,*q,*r; int p[8][2]={100,120,160,50,180,100,200,80,240,160,210,220,170,160,140,190}; int i; setcolor(12); for (i=0;i<7;i++) line(p[i][0],p[i][1],p[i+1][0],p[i+1][1]); line(p[0][0],p[0][1],p[7][0],p[7][1]); rectangle(120,200,230,70); h=NULL; for (i=0;i<8;i++) { q=(struct node *)malloc(LEN); q->dx=p[i][0]; q->dy=p[i][1]; if (h==NULL) h=q; else r->next=q; r=q; } r->next=NULL; return(h);}struct node *builx(h,x)struct node *h; int x;{int s[2],j[2];struct node *hh,*p,*r,*q;int max,min; p=h; hh=NULL; s[0]=p->dx; s[1]=p->dy; p=p->next; while (p!=NULL) { j[0]=x; j[1]=s[1]+(p->dy-s[1])*(x-s[0])/(p->dx-s[0]); max=s[0]; min=p->dx; if (s[0]<p->dx) { max=p->dx; min=s[0]; } if ((j[0]>=min)&&(j[0]<=max)) { q=(struct node *)malloc(LEN); q->dx=j[0]; q->dy=j[1]; if (hh==NULL) hh=q;else r->next=q; r=q; } if (p->dx>=x) { q=(struct node *)malloc(LEN); q->dx=p->dx; q->dy=p->dy; if (hh==NULL) hh=q; else r->next=q; r=q; } s[0]=p->dx; s[1]=p->dy; p=p->next; } p=h; j[0]=x; j[1]=s[1]+(p->dy-s[1])*(x-s[0])/(p->dx-s[0]); max=s[0]; min=p->dx; if (s[0]<p->dx) { max=p->dx; min=s[0]; } if ((j[0]>=min)&&(j[0]<=max)) { q=(struct node *)malloc(LEN); q->dx=j[0]; q->dy=j[1]; if (hh==NULL) hh=q; else r->next=q; r=q; } if (p->dx>=x) { q=(struct node *)malloc(LEN); q->dx=p->dx; q->dy=p->dy; if (hh==NULL) hh=q; else r->next=q; r=q; } r->next=NULL; return(hh); }
|