0

Description

An unit rectangle has coordinates (0,0), (0,1), (1,0) and (1,1). A random number for x-axis and another random number for y-axis is generated in range 0 to 1. So they make a random coordinate.

Suppose the random coordinate is (M,N). So it subdivide the unit square into 4 sub-rectangles. Lets label them in a clockwise fashion like this picture- http://bit.ly/15TsSw6.
To determine the area of that sub-rectangles I used-

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;
}

Here's my problem:

Now let another set of coordinates are randomly generated. It will split one of those sub-rectangle another 4 blocks. This process will continue 100 times. And each time the randomly generated coordinates splits the rectangle near it into (3j+1) subrectangles (See the picture: http://bit.ly/11xyTOb).
How can I calculate the area of the sub-rectangles each time?[Edited]

4

1 回答 1

0

该算法可能是这样的。您将需要一个递归函数 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);
    }
  }
}
于 2013-06-07T19:35:58.073 回答