Author Topic: Find out all the enclosed area algorithm!  (Read 2511 times)

0 Members and 1 Guest are viewing this topic.

Q1241274614

  • Guest
Find out all the enclosed area algorithm!
« on: September 20, 2012, 09:01:46 AM »
Find out all the enclosed area algorithm!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

chlh_jd

  • Guest
Re: Find out all the enclosed area algorithm!
« Reply #2 on: September 20, 2012, 11:29:24 AM »
To simple four points polygon , can use delaunay triangles .
To complex case , Use widding number or the method Alan suggested .
Code: [Select]
(bpoly point <Selection> [Point] )
The following codes is only expressed ideas
Code: [Select]
(defun c:test  (/  f1 ss ssobj a b m ip ips p0 l res)
  (defun f1 (a b)
    (if (equal (cadr a) (cadr b) 1.)
   (<= (car a) (car b))
   (<= (cadr a) (cadr b))
)
    )   
  (setq ss (ssget))
  (setq ssobj (ss2lst ss T))
  (while (cadr ssobj)
    (setq a (car ssobj)
  ssobj (cdr ssobj))
    (foreach b ssobj
      (if (not
    (minusp
      (vlax-safearray-get-u-bound
(vlax-variant-value
  (setq m (vla-IntersectWith
    a
    b
    0
    )))
1)))
(setq ip  (list-comp
    (vlax-safearray->list (vlax-variant-value m))
    3)
      ips (append ip ips)))))
  (if (> (length ips) 3)
    (progn     
      (setq l (ss-△ ips));_delaunay tri , Written by  ElpanovEvgeniy 
      (setq l (mapcar (function (lambda (x)
  (vl-sort x (function (lambda (a b)
(f1 a b))))))l));_sort every triangle's points by x y
      (setq l (vl-sort l
       (function (lambda (x y / an1 an2 d1 d2)
   (f1 (car x) (car y))    
   ))));_sort triangles by left-down point's x y
      (while (cadr l)
(setq a (car l)
      b (cadr l)
      l (cddr l))
(setq a (remove-eq-doubles (append a b) 1e-6))
(setq a (reverse(sort-ad a (midpts a))))
(setq res (cons a res))
)
      (if l
(setq res (append l res)))
      (foreach a  res
(setq d (* (distance (car a) (caddr a)) -0.05))
(setq b (offsetpts a d))
(draw-pl (list b (cons 62 3)))
(mapcar (function (lambda (x y)
    (entmake (list (cons 0 "LINE")
   (cons 10 x)
   (cons 11 y)
   (cons 62 3)))))
a
b))
      ))
  (princ)
  )
« Last Edit: September 20, 2012, 11:33:58 AM by chlh_jd »

chlh_jd

  • Guest
Re: Find out all the enclosed area algorithm!
« Reply #3 on: September 20, 2012, 11:49:28 AM »
General to compare operating efficiency , Lisp>VLisp> VLA> COMMAND ,  so try Lisp&VLisp functions .

Q1241274614

  • Guest
Re: Find out all the enclosed area algorithm!
« Reply #4 on: September 20, 2012, 11:52:08 AM »
1.(setq l (ss-△ ips));_delaunay tri , Written by  ElpanovEvgeniy  ?
2.(setq b (offsetpts a d))?点集的偏移点位吗?

thank!

zoltan

  • Guest
Re: Find out all the enclosed area algorithm!
« Reply #5 on: September 20, 2012, 05:52:28 PM »
Are you using the Boundary command to find the boundaries, or are you creating them yourself?
« Last Edit: September 20, 2012, 06:00:46 PM by zoltan »

chlh_jd

  • Guest
Re: Find out all the enclosed area algorithm!
« Reply #6 on: September 20, 2012, 10:56:46 PM »
1.(setq l (ss-△ ips));_delaunay tri , Written by  ElpanovEvgeniy  ?
2.(setq b (offsetpts a d))?点集的偏移点位吗?
thank!
Evgeniy's codes for cal delaunay triangles can be found in TheSwamp.
offsetpts function is offset colesed polygon's points , if d minusp , inward offset , if d plusp , outward offset
             it's not the key function , just to deal the each loop to the result like you post gif.
« Last Edit: September 20, 2012, 10:59:59 PM by chlh_jd »