天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 78|回复: 0

Ojectarx之无序点集逆时针排序

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
//若点a大于点b,即点a在点b顺时针方向,返回true,否则返回false
bool PointCmp(AcGePoint2d& a,AcGePoint2d& b,AcGePoint2d& center)
{
if (a.x >= 0 && b.x < 0)
return true;
if (a.x == 0 && b.x == 0)
return a.y > b.y;
//向量OA和向量OB的叉积
int det = (a.x - center.x) * (b.y - center.y) - (b.x - center.x) * (a.y - center.y);
if (det < 0)
return true;
if (det > 0)
return false;
//向量OA和向量OB共线,以距离判断大小
int d1 = (a.x - center.x) * (a.x - center.x) + (a.y - center.y) * (a.y - center.y);
int d2 = (b.x - center.x) * (b.x - center.y) + (b.y - center.y) * (b.y - center.y);
return d1 > d2;
}
void CCommonFunction::ClockwiseSortPoints(AcGePoint2dArray &vPoints)
{
//计算重心
AcGePoint2d centerstruct;
double x = 0,y = 0;
for (int i = 0;i < vPoints.length();i++)
{
x += vPoints[i].x;
y += vPoints[i].y;
}
centerstruct.x = x/vPoints.length();
centerstruct.y = y/vPoints.length();

//冒泡排序
for(int i = 0;i < vPoints.length() - 1;i++)
{
for (int j = 0;j < vPoints.length() - i - 1;j++)
{
if (PointCmp(vPoints[j],vPoints[j+1],centerstruct))
{
AcGePoint2d tmp = vPoints[j];
vPoints[j] = vPoints[j + 1];
vPoints[j + 1] = tmp;
}
}
}
}

 

 

 

 

Ojectarx之无序点集逆时针排序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 10:29 , Processed in 0.142371 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表