配置したいエリアはというと、距離的にフリースローからスリーポイントまでの間にあたる扇状の青の部分です
操作の都合上、リングの左右側の鋭角を10°程削っています
これをどう計算してランダムな座標を生成するか
もし対象とするエリアが長方形だったりすると話は簡単です
XとY軸の対象範囲をRandom.nextInt(value)するだけ
Rect area = new Rect(100, 100, 400, 300); Random random =new Random(); int x = area.left + random.nextInt(area.width()); int y = area.top + random.nextInt(area.height());試しに1000個ほど生成して描画してみましょう
Rect area = new Rect(100, 100, 400, 300);
canvas.drawRect(area, paint);
Random random =new Random();
for (int i = 0; i < 1000; i++) {
int x = area.left + random.nextInt(area.width());
int y = area.top + random.nextInt(area.height());
canvas.drawCircle(x, y, 3f, paint);
}
なんか今回は変形扇形のエリアではいろいろと方法はあると思いますが、このような考え方で生成しました
赤枠部分フリースローラインからスリーポイントラインまでの範囲でランダムにセットした座標を、対象範囲角をランダムにセットして回転する
ソースとしてはこのような感じ
Random random =new Random();
Plot ring = new Plot(7500, 1882);
for (int i = 0; i < 1000; i++) {
//リングX座標+フリースローラインまでの距離(4.118m)+フリースローラインからスリーポイントラインの間(2.52m)の間のランダム値
Plot base = new Plot(ring.x + 4118 + ((2520 * random.nextInt(100)) / 100), ring.y);
//削った10度+配置部分160°のランダム値
int angle = 10 + random.nextInt(160);
//回転処理
Plot pos = Utl.rotate(angle, ring, base);
//描画座標変換
pos = Court.getDPlot(pos);
canvas.drawCircle(pos.x, pos.y, 3f, paint);
}
試しに1000個ほど生成して描画よさそうです




0 件のコメント:
コメントを投稿