• 大小: 2KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-10-20
  • 语言: C/C++
  • 标签: C  

资源简介

用c写的道格拉斯普克算法,是对点的压缩存储及其有效的一种方法

资源截图

代码片段和文件信息

#include
#include
#include
#include
#define NULL 0
#define LEN sizeof(struct point)

struct point
{
char ptname[8];
float x;
float y;
struct point *next;
};

struct point* creat(void)
{
struct point *head;
struct point *p1*p2;
int n=0;
p1=p2=(struct point*)malloc(LEN);
scanf(“%s“p1->ptname);
head=NULL;
while(strcmp(p1->ptname“finish“)!=0)
{
printf(“请输入该点X Y坐标\n“);
scanf(“%f%f“&p1->x&p1->y);
n=n+1;
if(n==1) 
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct point*)malloc(LEN);
printf(“请输入下一点点名\n“);
scanf(“%s“p1->ptname);
}
p2->next=NULL;
return(head);
}

struct point *getlast(struct point *p)
{
while(p->next!=NULL)
p=p->next;
return p;
}

float len(float x1float y1float x2float y2float x3float y3)
{
float abcsh;
a=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
b=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
c=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
s=0.5*(a+b+c);
h=(sqrt(s*(s-a)*(s-b)*(s-c)))*2/c;
return h;
}

void doglas(struct point *headstruct point *lastfloat si

评论

共有 条评论