Author Topic: How to divide composite shapes into rectangles?  (Read 1900 times)

0 Members and 1 Guest are viewing this topic.

litss

  • Guest
How to divide composite shapes into rectangles?
« on: October 22, 2006, 01:27:22 AM »
As the following Fig shows, I know how to unite several rectangles into one by using the "region" command. But what I really want is to do the reverse. I wish I could get each"rect" from the united shapes. Would there be a good idea about this? thx!

sinc

  • Guest
Re: How to divide composite shapes into rectangles?
« Reply #1 on: October 22, 2006, 02:13:55 AM »
Do they need to be closed figures?  Or can you just EXTEND lines until you just can't EXTEND no more, so to speak?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to divide composite shapes into rectangles?
« Reply #2 on: October 22, 2006, 06:24:52 AM »
Quote
As the following Fig shows, I know how to unite several rectangles into one by using the "region" command.
Figures 1 and 2 are the same starting shape.
So are figures 3 and 4.
.. in fact figure 5 is almost a match to figure 4 .. depends on the rules :-)

You'd need some pretty complicated rules to make the decisions programmatically.
« Last Edit: October 22, 2006, 06:27:16 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

litss

  • Guest
Re: How to divide composite shapes into rectangles?
« Reply #3 on: October 22, 2006, 08:21:04 AM »
Quote
Do they need to be closed figures?  Or can you just EXTEND lines until you just can't EXTEND no more, so to speak?
In my program, it has to be a colsed figure. What I want is the point lists of all the rects. just by "extend" wouldn't work.
Quote
.. in fact figure 5 is almost a match to figure 4 .. depends on the rules

You'd need some pretty complicated rules to make the decisions programmatically
Yes, many of them comes from the same starting shapes-two or three, or maybe four....rects. Acturally, we can recognize all the rects in the shapes at the first sight. But to get them (the point list) by program is so hard.:(  What's the rules between them...

the following is my routine. It can solve the "L" or "T" shape. But I want more...

Code: [Select]
;test: for test
(defun c:test (/ e i pt ptn )
  (SETVAR "OSMODE" 0)
  (setq e (vlax-ename->vla-object (car (entsel "\nPlsease select a colsed pline: ")))
        i -1
        ptn '()
  )
  (while (setq pt (vlax-curve-getPointAtParam e (setq i (1+ i))))
    (setq ptn (cons pt ptn))
  )
  (sub ptn)
);test
;sub: to find out the rects from a colosed "L" or "T" shape.
(defun sub (ptn / n0 n1 n2 n3 pnum pt0 pt1 pt2 pt3 ptn)
  (setq pnum (sub4 ptn 0 -1))
  (setq n0 (nth 0 pnum))
  (setq n1 (nth 1 pnum))
  (setq pnum (sub4 ptn 0 1))
  (setq n2 (nth 0 pnum))
  (setq n3 (nth 1 pnum))
  (if (< (cadr (nth n0 ptn)) (cadr (nth n3 ptn)))
    (setq pt0 (list (car (nth n0 ptn)) (cadr (nth n3 ptn))))
    (setq pt0 (nth n0 ptn))
  );if
  (if (> (cadr (nth n2 ptn)) (cadr (nth n1 ptn)))
    (setq pt2 (list (car (nth n2 ptn)) (cadr (nth n1 ptn))))
    (setq pt2 (nth n2 ptn))
  );if
  (command "-color" "1")
  (command "rectang" pt0 pt2);draw the first rectangle
  (setq pnum (sub4 ptn 1 -1))
  (setq n0 (nth 0 pnum))
  (setq n1 (nth 1 pnum))
  (setq pnum (sub4 ptn 1 1))
  (setq n2 (nth 0 pnum))
  (setq n3 (nth 1 pnum))
  (setq pt1 (list (max
                    (car (nth n0 ptn))
                    (car (nth n3 ptn))
                  ) (min
                      (cadr (nth n0 ptn))
                      (cadr pt0)
                    )
            )
  )
  (setq pt3 (list (min
                    (car (nth n1 ptn))
                    (car (nth n2 ptn))
                  ) (max
                      (cadr (nth n2 ptn))
                      (cadr pt2)
                    )
            )
  )
  (command "-color" "2")
  (command "rectang" pt1 pt3);draw the second rectangle

)
;sub4: to arange
(defun sub4 (ptn axi cp / n n0 n1 nt pnum)
  (setq n (vl-list-length ptn))
  (setq n0 0)
  (setq n1 0)
  (while (> (setq n (1- n))
            0
         )
    (if (> (* cp (nth axi (nth n ptn))) (* cp (nth axi (nth n0 ptn))))
      (setq n0 n)
    )
  )
  (setq n (vl-list-length ptn))
  (while (> (setq n (1- n))
            -1
         )
    (if (equal (nth axi (nth n ptn)) (nth axi (nth n0 ptn)) 5)
      (if (/= n n0)
        (setq n1 n)
      );if
    );if
  );while
  (setq axi (abs (- axi 1)))
  (if (> (* cp (nth axi (nth n1 ptn))) (* cp (nth axi (nth n0 ptn))))
    (progn
      (setq nt n1)
      (setq n1 n0)
      (setq n0 nt)
    );progn
  );if
  (setq pnum (list n0 n1))
  pnum
)