所以我在 Windows 窗体应用程序中得到了一个圆圈,并且必须在这个圆圈中放置 20 个随机点。我的想法是将圆圈分成 4 部分以使其更加平衡。我的问题是这些点都是在中间产生的,我不知道如何解决这个问题......
Graphics g;
Pen p;
Random r = new Random();
int[] KegelX = new int[20];
int[] KegelY = new int[20];
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Kegelplatzierung();
p = new Pen(Color.Black);
g = this.CreateGraphics();
g.DrawEllipse(p, new Rectangle(50, 50, 400, 400));
for (int i = 0; i < 20; i++)
{
g.DrawEllipse(p, new Rectangle(KegelX[i], KegelY[i], 1, 1));
}
p.Dispose();
g.Dispose();
}
private void Kegelplatzierung() {
for (int i = 0; i < 5; i++)
{
bool Kriterium = false;
while (!Kriterium)
{
KegelX[i] = r.Next(50, 250);
KegelY[i] = r.Next(50, 250);
if (Math.Sqrt((250 - KegelX[i]) ^ 2 + (KegelY[i] - 250) ^ 2) < 200)
{
Kriterium = true;
}
}
}
for (int i = 5; i < 10; i++)
{
bool Kriterium = false;
while (!Kriterium)
{
KegelX[i] = r.Next(250, 450);
KegelY[i] = r.Next(50, 250);
if (Math.Sqrt((KegelX[i] - 250) ^ 2 + (KegelY[i] - 250) ^ 2) < 200)
{
Kriterium = true;
}
}
}
for (int i = 10; i < 15; i++)
{
bool Kriterium = false;
while (!Kriterium)
{
KegelX[i] = r.Next(50, 250);
KegelY[i] = r.Next(250, 450);
if (Math.Sqrt((250 - KegelX[i]) ^ 2 + (250 - KegelY[i]) ^ 2) < 200)
{
Kriterium = true;
}
}
}
for (int i = 15; i < 20; i++)
{
bool Kriterium = false;
while (!Kriterium)
{
KegelX[i] = r.Next(250, 450);
KegelY[i] = r.Next(250, 450);
if (Math.Sqrt((KegelX[i] - 250) ^ 2 + (250 - KegelY[i]) ^ 2) < 200)
{
Kriterium = true;
}
}
}
}
示例: http: //puu.sh/gB6Dg/e81f8c3486.png http://puu.sh/gB6Ec/306f61424c.png
感谢帮助!