私はこのようなことをしなければなりません。ランダムな要素(座標)
私はノードをクリックすると、それが拡大し、これは(私はそれを行うにはPowerchartsを使用しています)OKです。 大きな問題は、サブノードを開いたときに他のノード/サブノードと重ならないようにランダムな座標を作成することです。
私は座標を渡す必要があるので、大きな問題はそれを渡すことです。
私はC#でランダム座標を行う必要があります。
// -------------------------------------------- -----------
これは私がこれまでにやったことです:
これはoverlapingされていない、私は何をすべきかですが、私は問題を抱えています。 出発点からサークルを始めるにはどうすればよいですか?たとえば、 は、中央(300,300)から開始し、その周りに円を描きます。可能だ?
private void button2_Click(object sender, EventArgs e)
{
g = pictureBox1.CreateGraphics();
g.Clear(pictureBox1.BackColor);
double angle;
Circle item0 = new Circle();
item0.x=200;
item0.y=150;
item0.r=50;
listaCirculos.Add(item0);
Random randomMember = new Random();
g.DrawEllipse(pen1, 200, 150, 50, 50);
while(listaCirculos.Count!=11)
{
int[] it = GenerateNewCircle(600);
Circle item = new Circle();
item.x = it[0];
item.y = it[1];
item.r = 50;
if (circleIsAllowed(listaCirculos, item))
{
listaCirculos.Add(item);
g.DrawEllipse(pen1, Convert.ToInt32(item.x), Convert.ToInt32(item.y), 50, 50);
}
}
}
bool circleIsAllowed(List<Circle> circles, Circle newCircle)
{
foreach(Circle it in circles)
{
//double sumR = it.x + newCircle.r;
//double dx = it.x - newCircle.x;
//double dy = it.y - newCircle.y;
//double squaredDist = dx * dx + dy * dy;
double aX = Math.Pow(it.x - newCircle.x, 2);
double aY = Math.Pow(it.y - newCircle.y, 2);
double Dif = Math.Abs(aX - aY);
double ra1 = it.r/2;
double ra2 = it.r/2;
double raDif = Math.Pow(ra1 + ra2, 2);
if ((raDif + 1) > Dif) return false;
//if (squaredDist < sumR*sumR) return false;
}
return true; // no existing circle overlaps
}
public int[] GenerateNewCircle(int maxSize)
{
int x, y;
Random randomMember = new Random();
x = randomMember.Next(0,maxSize);
if (x - 50 < 0)
y = randomMember.Next(x + 50, maxSize);
else if (x + 50 > 600)
y = randomMember.Next(0, x - 50);
else
// in this case, x splits the range 0..n into 2 subranges.
// get a random number and skip the "gap" if necessary
y = randomMember.Next(0, maxSize - 50);
if (y > x - 50)
{
y += 20;
}
int[] abc = new int[2];
abc[0] = x;
abc[1] = y;
return abc;
}
Hmmm、実際の問題を解決するのではなく、ブルートフォースのアプローチを取っています。また、リストにポイントオブジェクトが含まれているかどうかを確認しています... –
MoarCodePlz
申し訳ありませんが、私は間違っていますしかし、今私は正しいと思います。 – hashi
こんにちは、ほぼそうですが、長方形が別のものと重なっていないかどうかを確認するにはどうすればいいですか? – Luis