【问题标题】:split unit square into n subrectangle from randomly generated coordinates从随机生成的坐标中将单位正方形拆分为 n 个子矩形
【发布时间】:2013-06-07 18:42:11
【问题描述】:

说明

单位矩形具有坐标 (0,0)、(0,1)、(1,0) 和 (1,1)。 x 轴的随机数和 y 轴的另一个随机数在 0 到 1 的范围内生成。因此它们生成了一个随机坐标。

假设随机坐标为 (M,N)。所以它将单位正方形细分为4个子矩形。让我们像这张图片一样以顺时针方式标记它们-http://bit.ly/15TsSw6。
为了确定我使用的子矩形的面积-

void area1(double a[],double ax[],double ay[])
{
   ax[0]=M;
   ay[0]=1-N;
   a[0]= ax[0]*ay[0]; //area of first block

   ax[1]=1-M;
   ay[1]=ay[0];
   a[1]=ax[1]*ay[1]; //area of second block

   ax[2]=ax[1];
   ay[2]=N;
   a[2]=ax[2]*ay[2]; //area of third block

   ax[3]=M;
   ay[3]=N;
   a[3]=ax[3]*ay[3]; //area of fourth block

   cout<<endl;
}

这是我的问题:

现在让另一组坐标随机生成。它将这些子矩形中的一个再拆分 4 个块。这个过程将持续 100 次。并且每次随机生成的坐标将其附近的矩形分割成(3j+1)个子矩形(见图:http://bit.ly/11xyTOb)。
每次如何计算子矩形的面积?[已编辑]

【问题讨论】:

  • 矩形的面积保持不变。 1 unit^2
  • 正如阿明所写,总面积保持不变,但我想这不是你的意思。那么你要计算什么面积呢?
  • 是的,总面积保持不变。我想计算子矩形被随机分割后的面积。

标签: c++ rectangles


【解决方案1】:

算法可能是这样的。 你需要一个递归函数 开始时 feed count=1

void calculatearea(coordinates of 4 corners of the rectangle,count)
{
  if count < 100
  {
    calculate area of the rectangle;
    generate random numbers;
    generate corners of the 4 new rectangles;
    for each new rectangle i
    {
      calculatearea(corners of rectangle i, count+1);
    }
  }
}

【讨论】:

    猜你喜欢
    • 2014-06-08
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    • 2013-02-08
    • 2020-04-21
    • 2022-01-18
    相关资源
    最近更新 更多