# 计算机图形学-有效边表算法源代码(共11页).docx

1/11

• 1.该资料是网友上传的，本站提供全文预览，预览什么样，下载就什么样。
• 2.下载该文档所得收入归上传者、原创者。
• 3.下载的文档，不会出现我们的网址水印。
1/11 下载此文档

#include <>
#utDisplayFunc(Display);
Initial();
glutMainLoop();
return 0;
}
//比较2个点的高度
int compare(Point p1, Point p2)
{
if ( > )
return 1;
else if ( == )
return 0;
return -1;
}

//由点数组生成线段数组
Line* create_lines(Point points[], int n)
{
Line *lines = (Line*)malloc(n * sizeof(Line));
for (int i = 0; i < n; ++i)
{
Point p1 = points[i];
Point p2 = points[(i + 1) % n];
int result = compare(p1, p2);
if (result == 0)
lines[i].is_active = 0;
else
lines[i].is_active = 1;
lines[i].high_point = result > 0 ? p1 : p2;
lines[i].low_point = result < 0 ? p1 : p2;
lines[i].inverse_k = (double)( - ) / (double)( - );
}
return lines;
}
//获取线数组中最低的端点
Point get_lowest_point(Line lines[], int n)
{
Point lowest_point = lines[0].low_point;
for (int i = 1; i < n; ++i)
{
Point low_point = lines[i].low_point;
if (compare(lowest_point, low_point) > 0)
lowest_point = low_point;
}
return lowest_point;
}
//获取线数组中最高的端点
Point get_highest_point(Line lines[], int n)
{
Point highest_point = lines[0].high_point;

for (int i = 1; i < n; ++i)
{
Point high_point = lines[i].high_point;
if (compare(highest_point, high_point) < 0)
highest_point = high_point;
}
return highest_point;
}
//交换2个Line对象
void swap(Line &l1, Line &l2)
{
Line temp = l1;
l1 = l2;
l2 = temp;
}
//对线数组进行排序
void sort(Line lines[], int n)
{
//先按低端点的y坐标进行升序排序
for (int i = 0; i < n; ++i)
{
int min_index = i;
for (int j = i + 1;

• 页数11
• 收藏数0 收藏
• 顶次数0
• 上传人ogthpsa
• 文件大小15 KB
• 时间2022-04-08