Author Topic: stack rectangles  (Read 1761 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
stack rectangles
« on: July 24, 2016, 01:28:26 AM »
I am trying to stack rectangles between certain distances inside a selected polyline. I have the east west figured out, but not sure how to solve the north south at the same time.  Any help appreciated.

Code - C#: [Select]
  1.  ObjectId rectangleboundary = CreateRectangle(pline.GeometricExtents.MinPoint, pline.GeometricExtents.MaxPoint);
  2.  
  3.                 double eastwestdist = Math.Abs(pline.GeometricExtents.MinPoint.X - pline.GeometricExtents.MaxPoint.X);
  4.                 double northsouthdist = Math.Abs(pline.GeometricExtents.MinPoint.Y - pline.GeometricExtents.MaxPoint.Y);
  5.  
  6.                 double topleftx = pline.GeometricExtents.MinPoint.X;
  7.                 double toplefty = pline.GeometricExtents.MaxPoint.Y;
  8.                 Point3d topleft = new Point3d(topleftx,toplefty,0);
  9.  
  10.                 double distance = 30;
  11.                 double checkhorz = 0;
  12.  
  13.                 while (checkhorz < eastwestdist)
  14.                 {
  15.                      rectangleboundary = CreateRectangle(new Point3d(topleft.X + checkhorz,topleft.Y,0), new Point3d(topleft.X + checkhorz + distance, topleft.Y - distance, 0));
  16.                     checkhorz = checkhorz + distance;
  17.                 }

Thanks!

« Last Edit: July 24, 2016, 01:42:32 AM by Area51Visitor »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: stack rectangles
« Reply #1 on: July 24, 2016, 03:11:15 AM »
Hi,

Here's a way:

Code - C#: [Select]
  1.                 var extents = pline.GeometricExtents;
  2.                 CreateRectangle(extents.MinPoint, extents.MaxPoint);
  3.  
  4.                 int eastwestNum = (int)((extents.MaxPoint.X - extents.MinPoint.X) / 30.0);
  5.                 int northsouthNum = (int)((extents.MaxPoint.Y - extents.MinPoint.Y) / 30.0);
  6.  
  7.                 Vector3d horizDisp = new Vector3d(30.0, 0.0, 0.0);
  8.                 Vector3d vertDisp = new Vector3d(0.0, 30.0, 0.0);
  9.  
  10.                 Point3d p1 = new Point3d(extents.MinPoint.X, extents.MaxPoint.Y - 30.0, 0.0);
  11.                 Point3d p2 = p1 + horizDisp + vertDisp;
  12.  
  13.                 for (int i = 0; i < northsouthNum; i++)
  14.                 {
  15.                     Point3d ll = p1;
  16.                     Point3d ur = p2;
  17.                     for (int j = 0; j < eastwestNum; j++)
  18.                     {
  19.                         CreateRectangle(ll, ur);
  20.                         ll += horizDisp;
  21.                         ur += horizDisp;
  22.                     }
  23.                     p1 -= vertDisp;
  24.                     p2 -= vertDisp;
  25.                 }
« Last Edit: July 24, 2016, 03:30:03 AM by gile »
Speaking English as a French Frog

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: stack rectangles
« Reply #2 on: July 24, 2016, 03:42:50 AM »
Thank you giles, always

Hi,

Here's a way:

Code - C#: [Select]
  1.                 var extents = pline.GeometricExtents;
  2.                 CreateRectangle(extents.MinPoint, extents.MaxPoint);
  3.  
  4.                 int eastwestNum = (int)((extents.MaxPoint.X - extents.MinPoint.X) / 30.0);
  5.                 int northsouthNum = (int)((extents.MaxPoint.Y - extents.MinPoint.Y) / 30.0);
  6.  
  7.                 Vector3d horizDisp = new Vector3d(30.0, 0.0, 0.0);
  8.                 Vector3d vertDisp = new Vector3d(0.0, 30.0, 0.0);
  9.  
  10.                 Point3d p1 = new Point3d(extents.MinPoint.X, extents.MaxPoint.Y - 30.0, 0.0);
  11.                 Point3d p2 = p1 + horizDisp + vertDisp;
  12.  
  13.                 for (int i = 0; i < northsouthNum; i++)
  14.                 {
  15.                     Point3d ll = p1;
  16.                     Point3d ur = p2;
  17.                     for (int j = 0; j < eastwestNum; j++)
  18.                     {
  19.                         CreateRectangle(ll, ur);
  20.                         ll += horizDisp;
  21.                         ur += horizDisp;
  22.                     }
  23.                     p1 -= vertDisp;
  24.                     p2 -= vertDisp;
  25.                 }