嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
private void Compute()
{
for (int i = 0; i < 100; i )
{
double distance = -1;
for (int j = 0; j < 4; j )
{
int tempDistance = (this.Center[j].X - this.Points[i].X) * (this.Center[j].X - this.Points[i].X) (this.Center[j].Y - this.Points[i].Y) * (this.Center[j].Y - this.Points[i].Y);
if ((Math.Sqrt(tempDistance) < distance) || j == 0)
{
distance = Math.Sqrt(tempDistance);
Points[i].Focus = j;
}
}
}
}
/// <summary>
/// 更新中心
/// </summary>
private void UpdateCenter()
{
for (int i = 0; i < this.K; i )
{
int x = 0, y = 0, count = 0;
for (int j = 0; j < 100; j )
{
if (Points[j].Focus == i)
{
x = Points[j].X;
y = Points[j].Y;
count ;
}
}
//利用三目运算符,防止出现除以0的不合法运算
x = x / (count == 0 ? 1 : count);
y = y / (count == 0 ? 1 : count);
Center[i].X = x;
Center[i].Y = y;
}
}