Author Topic: ==={Challenge}===Find the ridge lines of sloped roof  (Read 106877 times)

0 Members and 5 Guests are viewing this topic.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #75 on: February 22, 2014, 10:12:34 AM »
chlh_jd... But to use 2droof3d.lsp, you have to have 2d soultion firstly created... You just selected LWPOLYLINE without 2D solution ridge lines... And I suggest that you use simple 2droof3d.lsp - not the old version... As for the above example, I agree that this HP.lsp solution can be derived from built-in EXTRUDE - TAPER command, but then you'll miss possible other soultions like I showed on left example... Both are correct and more over - to my opinion, left solution is much nicer as in practical possible realization reasons there are no close ridge edges that collapse into top apex... There is much nicer top ridge that is then continued to transform into porche roof mass that is attached to main roof solution...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

chlh_jd

  • Guest
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #76 on: February 22, 2014, 10:13:56 PM »
chlh_jd... But to use 2droof3d.lsp, you have to have 2d soultion firstly created... You just selected LWPOLYLINE without 2D solution ridge lines... And I suggest that you use simple 2droof3d.lsp - not the old version... As for the above example, I agree that this HP.lsp solution can be derived from built-in EXTRUDE - TAPER command, but then you'll miss possible other soultions like I showed on left example... Both are correct and more over - to my opinion, left solution is much nicer as in practical possible realization reasons there are no close ridge edges that collapse into top apex... There is much nicer top ridge that is then continued to transform into porche roof mass that is attached to main roof solution...
I'll test 2droof3d.lsp later, I don't think the Left result in your above example is right , just I reply following it . One boundary-line only One Roof-line , I think .

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #77 on: March 15, 2014, 05:48:41 PM »
2droof3d.lsp has been updated... Removed biggest boundary polyline from possible interaction within last lambda statement... Also previously created regions and lines successfully converted to LWPOLYLINES and removed from active document... (Implemented code from L.M. bbpoly.lsp posted here on this site)

http://www.theswamp.org/index.php?topic=10371.msg514603#msg514603

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #78 on: May 25, 2014, 04:57:37 AM »
Also changed hr.lsp - GP's modified version by me... Little change inside Maximum circumscribed circle subfunction...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

chlh_jd

  • Guest
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #79 on: May 31, 2014, 05:55:25 AM »
Use Command method dose not run in my computer (Acad2011 & Win7 64Bits)
here's my first version use Ray and Axis to construct roof line .
Code - Auto/Visual Lisp: [Select]
  1. (setq _2pi (+ pi pi)
  2.       _pi2 (/ pi 2.)
  3.       *gsls_debug* nil)
  4.  
  5. (defun ray-inters  (p0 an0 p1 an1 / p)
  6.   ;; intersection of two ray line
  7.   ;; an0 an1 -- [0 2pi)
  8.   (if (equal (angle p0 p1) an0 5e-5)
  9.     p1
  10.     (if
  11.       (and (setq p (inters p0 (polar p0 an0 1000.) p1 (polar p1 an1 1000.) nil))
  12.            (equal (angle p0 p) an0 5e-5)
  13.            (equal (angle p1 p) an1 5e-5))
  14.        p)))
  15.  
  16. (defun bisetor  (p0 p1 p2 / d a a0)
  17.   ;; Get inter bisetor of counterclockwise point set
  18.   ;; p0 p1 p2 -- 3p of ccw polygon
  19.   ;; return inter-bisetor in [0 2pi)
  20.   (setq d (distance p0 p1)
  21.         a (- (setq a0 (angle p1 p0)) (angle p1 p2))
  22.         a (- a0 (/ (angle '(0 0) (list (* d (cos a)) (* d (sin a)))) 2.)))
  23.   (cond ((< a 0) (+ a _2pi))
  24.         ((>= a _2pi) (- a _2pi))
  25.         (a)))
  26. (defun bisetor2  (p0 p1 p2 p3)
  27.   ;; Get inter bisetor between line (p1 p0) with line (p2 p3)
  28.   ;; p0 p1 p2 p4-- 4p of ccw polygon
  29.   ;; return inter-bisetor in [0 2pi)
  30.   (setq p0 (mapcar (function +) (mapcar (function -) p2 p1) p0))
  31.   (if
  32.     (<= (car (trans (mapcar (function -) p0 p3) 0 (mapcar (function -) p2 p3))) 0)
  33.      (bisetor p0 p2 p3)
  34.      (bisetor p3 p2 p0)))
  35. ;;-----------------------------------------------------
  36. (defun lbisetor  (l / i)
  37.   (setq i -1)
  38.   (mapcar (function (lambda (p0 p1 p2)
  39.                       (setq i (1+ i))
  40.                       (cons i (bisetor p0 p1 p2))))
  41.           (cons (last l) l)
  42.           l
  43.           (append (cdr l) (list (car l)))))
  44. ;;
  45. (defun format-i  (i n)
  46.   (cond ((< i 0) (+ n i))
  47.         ((>= i n) (- i n))
  48.         (i)))
  49.  
  50. ;;;Function : judge a point location with polygon
  51. ;;;Arg : pt -- a point
  52. ;;;      pts -- points of polygon
  53. ;;;      eps -- allowance
  54. ;;;return :
  55. ;;;     -1 -- out of polygon , 0 -- at , 1 -- in
  56. (defun pipl?  (pt pts eps / is at a)
  57.   ;; by &#29378;&#20992;  
  58.   ;; Edit by GSLS(SS) 2011.03.28
  59.   ;; Solved the problem : if a point at the given polygon , it perhap return T or NIL .  
  60.   (cond
  61.     ((vl-some (function (lambda (x) (equal x pt eps))) pts) 0)
  62.     ((and
  63.        (equal
  64.          (abs
  65.            (apply
  66.              (function +)
  67.              (mapcar
  68.                (function (lambda (x y / a)
  69.                            (setq a (rem (- (angle pt x) (angle pt y)) PI))
  70.                            (if (equal (+ (distance pt x) (distance pt y))
  71.                                       (distance x y)
  72.                                       Eps)
  73.                              (setq at T))
  74.                            a))
  75.                (cons (last pts) pts)
  76.                pts)))
  77.          pi
  78.          eps)
  79.        (not at))
  80.      1)
  81.     (at 0)
  82.     (-1)))
  83. ;; get closed polygon's area
  84. (defun ss-pts2area  (l)
  85.   (/ (apply (function +)
  86.             (mapcar (function (lambda (x y)
  87.                                 (- (* (car x) (cadr y)) (* (car y) (cadr x)))))
  88.                     (cons (last l) l)
  89.                     l)) 2.))
  90. ;; round
  91. (defun round  (a jd / b s)
  92.   (cond ((numberp a)
  93.          (setq b (expt 10.0 jd)
  94.                s (sign a))
  95.          (/ (fix (+ (* a b) (* 0.5 s))) b))
  96.         ((listp a)
  97.          (mapcar (function (lambda (a) (round a jd))) a))))
  98. ;;
  99. (defun sign  (x)
  100.   (cond ((minusp x) -1.)(1.0)))
  101. ;;
  102. (defun inzone?  (p p0 an0 p1 an1 / f a an2 an3 d)
  103.   (defun f  (a)
  104.     (cond ((< a 0) (+ a _2pi))
  105.           (a)))
  106.   (setq a   (angle p0 p1)
  107.         an0 (f (- an0 a))
  108.         an1 (f (- an1 a))
  109.         an2 (f (- (angle p0 p) a))
  110.         an3 (f (- (angle p1 p) a))
  111.         d   (car (trans (mapcar (function -) p p1) 0 (mapcar (function -) p0 p1))))
  112.   (and (<= an2 (+ an0 1e-3)) (>= an3 (- an1 1e-3)) (< d 0)))
  113.  ;|
  114. (defun c:test (/ p0 p1 p2 p3 an0 an1 p)
  115.   (setq p0 (getpoint "\nSelect CCW 4 Points -first :")
  116.         p1 (getpoint p0)
  117.         p2 (getpoint p1)
  118.         p3 (getpoint p2)
  119.         an0 (angle p1 p0)
  120.         an1 (angle p2 p3)
  121.         p0 p1 p1 p2)
  122.   (while (setq p (getpoint "\nSelect Determine point :"))
  123.     (if (inzone? p p0 an0 p1 an1)
  124.       (alert "In Zone.")
  125.       (alert "Out Zone."))))
  126. |;
  127.  
  128. (defun c:test  (/ list-inters _Pedal suit-i pnth add-item suit _closed foo foo1 ;_loacal functions
  129.                 e pl n i sl bl il rgl tl a b c a1 b1 c1 p p0 p1 p2 p3 closed_n
  130.                 closed_il rdl sti fi bi ip0 ip1 j0 j1 rml)
  131.   ;;  Find the ridge lines of sloped roof
  132.   ;;  V0.1  by GSLS(SS)  May 31 , 2014
  133.   ;;  
  134.   ;;------------------------------------local functions------------------------------;;
  135.   ;;
  136.   (defun list-inters  (a b)
  137.     (vl-remove-if-not (function (lambda (x)
  138.                                   (vl-position x a)))
  139.                       b))
  140.   ;;
  141.   (defun _Pedal  (p p1 p2)
  142.     (inters p (polar p (+ _pi2 (angle p1 p2)) 1e3) p1 p2 nil))
  143.   (defun suit-i  (i f)
  144.     (if (not (assoc 70 (nth i rgl)))
  145.       i
  146.       (suit-i (format-i (f i) n) f)))
  147.  
  148.   ;;
  149.   (defun pnth  (a)
  150.     (cond ((= (car a) 10) (nth (cdr a) pl))
  151.           ((nth (cdr a) tl))))
  152.   ;;
  153.   (defun add-item  (ti an chain / a b c d)
  154.     (setq a (car chain)
  155.           b (cadr chain)
  156.           c (cons 11 ti)
  157.           d (cons 12 an))
  158.     (cond ((member c chain)
  159.            (while (not (equal (car chain) c))
  160.              (setq chain (cdr chain)))
  161.            chain)
  162.           ((and an (= (car a) 12))
  163.            (cons (cons 12 an) (cons (cons 11 ti) (cdr chain))))
  164.           ((and (not an) (= (car a) 12))
  165.            (cons (cons 11 ti) (cdr chain)))
  166.           ((= (car a) 11)
  167.            (cond ((= (cdr a) ti)
  168.                   (cons (cons 12 an) chain))
  169.                  ((equal (nth ti tl) (nth (cdr a) tl) 1e-6)
  170.                   (cons (cons 12 an) chain))
  171.                  (chain)))
  172.           (chain)))
  173.   ;;
  174.   (defun suit  (p si / s p1 p2 pp d i ssl)
  175.     (setq s  (nth si sl)
  176.           p1 (nth (car s) pl)
  177.           p2 (nth (cadr s) pl)
  178.           pp (_pedal p p1 p2)
  179.           d  (distance p pp)
  180.           i  -1)
  181.     (setq ssl (vl-remove-if (function (lambda (a)
  182.                                         (setq i (1+ i))
  183.                                         (member i closed_il)))
  184.                             sl))
  185.     (setq sdl
  186.            (mapcar
  187.              (function (lambda (s / p1 p2 an1 an2 pp)
  188.                          (setq p1  (nth (car s) pl)
  189.                                p2  (nth (cadr s) pl)
  190.                                an1 (cdr (assoc (car s) bl))
  191.                                an2 (cdr (assoc (cadr s) bl))
  192.                                pp  (_pedal p p1 p2))
  193.                          (if (or (inzone? p p1 an1 p2 an2)
  194.                                  (equal (distance p1 p2)
  195.                                         (+ (distance p1 pp) (distance p2 pp))
  196.                                         1e-3))
  197.                            (distance p pp)
  198.                            (min (distance p p1) (distance p p2)))))
  199.              ssl))
  200.     (setq sdl (vl-sort sdl '<))
  201.     (not (vl-some (function (lambda (d1) (not (equal d d1 1e-3))))
  202.                   (vl-remove nil (list (car sdl) (cadr sdl) (caddr sdl)))))
  203.     )
  204.   ;; check closed
  205.   (defun _closed  ()
  206.     (if (< closed_n n)
  207.       (setq rgl
  208.              (mapcar
  209.                (function
  210.                  (lambda (r / a b c d e)
  211.                    (setq a (car r)
  212.                          b (cadr r)
  213.                          c (caddr r))
  214.                    (cond
  215.                      (c r)
  216.                      ((and (setq d (assoc 11 a)) (setq e (assoc 11 b)) (equal d e))
  217.                       (setq closed_n  (1+ closed_n)
  218.                             closed_il (cons (cdr (assoc 10 a)) closed_il))
  219.                       (list (member d a) (member e b) (cons 70 1)))
  220.                      ((list a b)))))
  221.                rgl))))
  222.   ;;------------------------------------main routine ------------------------------;;
  223.   (setq e (car (entsel "\nSelect a closed polygon :")))
  224.   (setq pl
  225.          (mapcar (function cdr)
  226.                  (vl-remove-if-not (function (lambda (a) (= (car a) 10))) (entget e))))
  227.   (if (< (ss-pts2area pl) 0) ;_force pointset CCW
  228.     (setq pl (reverse pl)))
  229.   ;; build side message
  230.   (setq n (length pl)
  231.         i -1)
  232.   (setq sl (mapcar (function (lambda (a)
  233.                                (setq i (1+ i))
  234.                                (if (= (1+ i) n)
  235.                                  (list i 0)
  236.                                  (list i (1+ i)))))
  237.                    pl))
  238.   ;; build inter-bisetor angle list with point index
  239.   (setq bl (lbisetor pl))
  240.   ;; for test
  241.   (if *gsls_debug* ;_(setq *gsls_debug* T)
  242.     (mapcar (function (lambda (a / p p1)
  243.                         (setq p  (nth (car a) pl)
  244.                               p1 (polar p (cdr a) 500.))
  245.                         (entmake (list (cons 0 "TEXT")
  246.                                        (cons 10 p)
  247.                                        (cons 1 (rtos (car a) 2 0))
  248.                                        (cons 40 1000.)
  249.                                        (cons 41 0.7)
  250.                                        (cons 50 0.0)))
  251.                         (entmake (list (cons 0 "LINE")
  252.                                        (cons 10 p)
  253.                                        (cons 11 p1)
  254.                                        (cons 8 "TEST")
  255.                                        (cons 62 3)))))
  256.             bl))
  257.   ;; build start result list , each side with two construction list
  258.   ;; dxf code : 10 -- point of pl , 11 -- point of tl (inter points) , 12 -- ray angle of last point  , 70 -- closed mark
  259.   (setq rgl
  260.          (mapcar
  261.            (function
  262.              (lambda (s)
  263.                (list (list (cons 12 (cdr (nth (car s) bl))) (cons 10 (car s)))
  264.                      (list (cons 12 (cdr (nth (cadr s) bl))) (cons 10 (cadr s))))))
  265.            sl))
  266.   ;; find first suitable ray-intersections
  267.   (setq il
  268.          (vl-remove
  269.            nil
  270.            (mapcar
  271.              (function
  272.                (lambda (s / s1 s2 p i)
  273.                  (setq s1 (nth (car s) bl) ;_(setq s (list 19 20))
  274.                        s2 (nth (cadr s) bl)
  275.                        p  (ray-inters (nth (car s1) pl)
  276.                                       (cdr s1)
  277.                                       (nth (car s2) pl)
  278.                                       (cdr s2)))
  279.                  (if
  280.                    (and
  281.                      p
  282.                      (> (pipl? p pl 1e-6) 0)
  283.                      (suit p (car s)))
  284.                     (list s p))))
  285.              sl)))
  286.   ;; add first suitable intersections into it's side info , put them closed .
  287.   (setq closed_n 0)
  288.   (foreach s  il
  289.     (setq p (round (cadr s) 6))
  290.     (if (not (setq i (vl-position p tl)))
  291.       (setq tl (append tl (list p))
  292.             i  (1- (length tl))))
  293.     (setq b         (nth (caar s) rgl)
  294.           b1        (list (add-item i nil (car b))
  295.                           (add-item i nil (cadr b))
  296.                           (cons 70 1))
  297.           rgl       (subst b1 b rgl)
  298.           closed_n  (1+ closed_n)
  299.           closed_il (cons (caar s) closed_il))
  300.     ;;deal near side info
  301.     (if (and (< closed_n n)
  302.              (setq bi (suit-i (format-i (1- (caar s)) n) 1-))
  303.              (setq fi (suit-i (cadar s) 1+))
  304.              (/= bi fi))
  305.       (setq a   (nth bi rgl)
  306.             c   (nth fi rgl)
  307.             p0  (nth (cdr (assoc 10 (car a))) pl)
  308.             p1  (nth (cdr (assoc 10 (cadr a))) pl)
  309.             p2  (nth (cdr (assoc 10 (car c))) pl)
  310.             p3  (nth (cdr (assoc 10 (cadr c))) pl)
  311.             an  (bisetor2 p0 p1 p2 p3)
  312.             a1  (list (car a) (add-item i an (cadr a)))
  313.             c1  (list (add-item i an (car c)) (cadr c))
  314.             rgl (subst a1 a rgl)
  315.             rgl (subst c1 c rgl))))
  316.   ;; deal has closed side .
  317.   (_closed)
  318.   ;; deal near side of closed-side , until catch another closed side
  319.   (if (< closed_n n)
  320.     (setq rdl (vl-remove-if-not (function (lambda (a) (assoc 70 a))) rgl)
  321.           rdl (mapcar (function (lambda (a / p pp d)
  322.                                   (if (assoc 11 (car a))
  323.                                     (setq p (pnth (assoc 11 (car a))))
  324.                                     (setq p (pnth (assoc 11 (cadr a)))))
  325.                                   (setq pp (_pedal p
  326.                                                    (pnth (assoc 10 (car a)))
  327.                                                    (pnth (assoc 10 (cadr a))))
  328.                                         d  (distance p pp))
  329.                                   (list d a)))
  330.                       rdl)
  331.           rdl (vl-sort rdl
  332.                        (function (lambda (a b)
  333.                                    (< (car a) (car b)))))))
  334.   (defun foo  ()
  335.     (while (and (< closed_n n)
  336.                 (/= bi fi)
  337.                 (setq a (nth bi rgl))
  338.                 (setq c (nth fi rgl))
  339.                 (not (assoc 70 a))
  340.                 (not (assoc 70 c))
  341.                 (vl-remove nil
  342.                            (list (setq ip0 (ray-inters (pnth (cadadr a))
  343.                                                        (cdaadr a)
  344.                                                        (pnth (cadar a))
  345.                                                        (cdaar a)))
  346.                                  (setq ip1 (ray-inters (pnth (cadar c))
  347.                                                        (cdaar c)
  348.                                                        (pnth (cadadr c))
  349.                                                        (cdaadr c)))))
  350.                 (setq p (pnth (cadar c)))
  351.                 (setq ip
  352.                        (cond
  353.                          ((and ip0 ip1)
  354.                           (cond
  355.                             ((and (> (setq j0 (pipl? ip0 pl 1e-6)) 0)
  356.                                   (> (setq j1 (pipl? ip1 pl 1e-6)) 0))
  357.                              (cond ((<= (distance p ip0) (distance p ip1))
  358.                                     (if (suit ip0 bi)
  359.                                       (cons "back" ip0)))
  360.                                    ((if (suit ip1 fi)
  361.                                       (cons "for" ip1)))))
  362.                             ((> (setq j0 (pipl? ip0 pl 1e-6)) 0)
  363.                              (if (suit ip0 bi)
  364.                                (cons "back" ip0)))
  365.                             ((> (setq j1 (pipl? ip1 pl 1e-6)) 0)
  366.                              (if (suit ip1 fi)
  367.                                (cons "for" ip1)))))
  368.                          ((and ip0 (> (setq j0 (pipl? ip0 pl 1e-6)) 0))
  369.                           (if (suit ip0 bi)
  370.                             (cons "back" ip0)))
  371.                          ((and ip1 (> (setq j1 (pipl? ip1 pl 1e-6)) 0))
  372.                           (if (suit ip1 fi)
  373.                             (cons "for" ip1))))))
  374.       (setq p (round (cdr ip) 6))
  375.       (if (not (setq i (vl-position p tl)))
  376.         (setq tl (append tl (list p))
  377.               i  (1- (length tl))))
  378.       (cond ((= (car ip) "for")
  379.              (setq c1        (list (add-item i nil (car c))
  380.                                    (add-item i nil (cadr c))
  381.                                    (cons 70 1))
  382.                    rgl       (subst c1 c rgl)
  383.                    closed_n  (1+ closed_n)
  384.                    closed_il (cons (cdr (assoc 10 (car c))) closed_il)
  385.                    fi        (format-i (1+ fi) n))
  386.              (if (= (suit-i (format-i fi n) 1+) bi)
  387.                (setq a1        (list (add-item i nil (car a))
  388.                                      (add-item i nil (cadr a))
  389.                                      (cons 70 1))
  390.                      rgl       (subst a1 a rgl)
  391.                      closed_n  (1+ closed_n)
  392.                      closed_il (cons (cdr (assoc 10 (car a))) closed_il))
  393.                (if (setq c (nth (suit-i (format-i fi n) 1+) rgl))
  394.                  (setq p2  (pnth (assoc 10 (car c)))
  395.                        p3  (pnth (assoc 10 (cadr c)))
  396.                        p0  (pnth (assoc 10 (car a)))
  397.                        p1  (pnth (assoc 10 (cadr a)))
  398.                        an  (bisetor2 p0 p1 p2 p3)
  399.                        a1  (list (car a) (add-item i an (cadr a)))
  400.                        rgl (subst a1 a rgl)
  401.                        c1  (list (add-item i an (car c)) (cadr c))
  402.                        rgl (subst c1 c rgl)))))
  403.             ((= (car ip) "back")
  404.              (setq a1        (list (add-item i nil (car a))
  405.                                    (add-item i nil (cadr a))
  406.                                    (cons 70 1))
  407.                    rgl       (subst a1 a rgl)
  408.                    closed_n  (1+ closed_n)
  409.                    closed_il (cons (cdr (assoc 10 (car a))) closed_il)
  410.                    bi        (format-i (1- bi) n))
  411.              (if (= (suit-i (format-i bi n) 1-) fi)
  412.                (setq c1        (list (add-item i nil (car c))
  413.                                      (add-item i nil (cadr c))
  414.                                      (cons 70 1))
  415.                      rgl       (subst c1 c rgl)
  416.                      closed_n  (1+ closed_n)
  417.                      closed_il (cons (cdr (assoc 10 (car c))) closed_il))
  418.                (if (setq a (nth (suit-i (format-i bi n) 1-) rgl))
  419.                  (setq p2  (pnth (assoc 10 (car c)))
  420.                        p3  (pnth (assoc 10 (cadr c)))
  421.                        p0  (pnth (assoc 10 (car a)))
  422.                        p1  (pnth (assoc 10 (cadr a)))
  423.                        an  (bisetor2 p0 p1 p2 p3)
  424.                        a1  (list (car a) (add-item i an (cadr a)))
  425.                        rgl (subst a1 a rgl)
  426.                        c1  (list (add-item i an (car c)) (cadr c))
  427.                        rgl (subst c1 c rgl)))))) ;_cond      
  428.       ))
  429.   ;;
  430.   (foreach s  rdl
  431.     (if (< closed_n n)
  432.       (progn
  433.         (setq sti (cdr (assoc 10 (caadr s))))
  434.         (setq fi (suit-i (format-i (1+ sti) n) 1+)
  435.               bi (suit-i (format-i (1- sti) n) 1-))
  436.         (foo)))) ;_foreach
  437.   ;; check closed  
  438.   (_closed)
  439.   ;; deal other no closed side
  440.   (defun foo1  (a)
  441.     (if (and (setq p (ray-inters (pnth (cadadr a))
  442.                                  (cdaadr a)
  443.                                  (pnth (cadar a))
  444.                                  (cdaar a)))
  445.              (> (pipl? p pl 1e-6) 0)
  446.              (suit p (cdr (assoc 10 (car a)))))
  447.       (progn
  448.         (setq p (round (cdr ip) 6))
  449.         (if (not (setq i (vl-position p tl)))
  450.           (setq tl (append tl (list p))
  451.                 i  (1- (length tl))))
  452.         (setq a1        (list (add-item i nil (car a))
  453.                               (add-item i nil (cadr a))
  454.                               (cons 70 1))
  455.               rgl       (subst a1 a rgl)
  456.               closed_n  (1+ closed_n)
  457.               closed_il (cons (cdr (assoc 10 (car a))) closed_il)
  458.               ))
  459.       (if (equal (angle (pnth (cadar a)) (pnth (cadadr a)))
  460.                  (cdaar a)
  461.                  1e-5) ;_collinear
  462.         (setq a1        (list (cons (cadadr a) (cdar a))
  463.                               (cdadr a)
  464.                               (cons 70 1))
  465.               rgl       (subst a1 a rgl)
  466.               closed_n  (1+ closed_n)
  467.               closed_il (cons (cdr (assoc 10 (car a))) closed_il))
  468.         (if (equal (cadadr a) (cadar a))
  469.           (setq a1        (list (cdar a) (cdadr a) (cons 70 1))
  470.                 rgl       (subst a1 a rgl)
  471.                 closed_n  (1+ closed_n)
  472.                 closed_il (cons (cdr (assoc 10 (car a))) closed_il))
  473.           (progn ;_force out routine ...
  474.             (princ "\n ***Error*** : ...")
  475.             (setq closed_n (1+ closed_n)))
  476.           ))))
  477.   (while (and (< closed_n n)
  478.               (setq rml (vl-remove-if (function (lambda (a) (assoc 70 a))) rgl)))
  479.     (cond
  480.       ((caddr rml)
  481.        (setq il
  482.               (vl-remove
  483.                 nil
  484.                 (mapcar
  485.                   (function
  486.                     (lambda (a / i p b)
  487.                       (setq i (vl-position a rgl))
  488.                       (if (and (setq p (ray-inters (pnth (cadadr a))
  489.                                                    (cdaadr a)
  490.                                                    (pnth (cadar a))
  491.                                                    (cdaar a)))
  492.                                (> (pipl? p pl 1e-6) 0)
  493.                                (suit p i)
  494.                                (setq b (list (cadar a) (cadadr a))))
  495.                         (list p i))))
  496.                   rml))) ;_
  497.        ;;
  498.        (if il
  499.          (foreach s  il
  500.            (if (< closed_n n)
  501.              (progn
  502.                (setq p (car s)
  503.                      b (nth (cadr s) rgl))
  504.                (if (not (setq i (vl-position p tl)))
  505.                  (setq tl (append tl (list p))
  506.                        i  (1- (length tl))))
  507.                (setq b1        (list (add-item i nil (car b))
  508.                                      (add-item i nil (cadr b))
  509.                                      (cons 70 1))
  510.                      rgl       (subst b1 b rgl)
  511.                      closed_n  (1+ closed_n)
  512.                      closed_il (cons (cdr (assoc 10 (car b))) closed_il))
  513.                (setq fi (suit-i (format-i (1+ (cdr (assoc 10 (car b)))) n) 1+)
  514.                      bi (suit-i (format-i (1- (cdr (assoc 10 (car b)))) n) 1-))
  515.                (setq a   (nth bi rgl)
  516.                      c   (nth fi rgl)
  517.                      p0  (nth (cdr (assoc 10 (car a))) pl)
  518.                      p1  (nth (cdr (assoc 10 (cadr a))) pl)
  519.                      p2  (nth (cdr (assoc 10 (car c))) pl)
  520.                      p3  (nth (cdr (assoc 10 (cadr c))) pl)
  521.                      an  (bisetor2 p0 p1 p2 p3)
  522.                      a1  (list (car a) (add-item i an (cadr a)))
  523.                      c1  (list (add-item i an (car c)) (cadr c))
  524.                      rgl (subst a1 a rgl)
  525.                      rgl (subst c1 c rgl))
  526.                (foo)))
  527.            )
  528.          (mapcar (function foo1) rml) ;_force deal
  529.          )
  530.        )
  531.       ((mapcar (function foo1) rml))) ;_cond
  532.     (_closed)
  533.     ) ;_while
  534.   ;; test result
  535.   (foreach r  rgl
  536.     (if (assoc 70 r)
  537.       (mapcar
  538.         (function (lambda (a)
  539.                     (setq b (mapcar (function (lambda (a) (pnth a))) a))
  540.                     (mapcar (function (lambda (c d)
  541.                                         (entmake (list (cons 0 "LINE")
  542.                                                        (cons 10 c)
  543.                                                        (cons 11 d)
  544.                                                        (cons 8 "Proof")
  545.                                                        (cons 62 1)))))
  546.                             b
  547.                             (cdr b))))
  548.         (list (car r) (cadr r)))))
  549.   (princ)
  550.   )
  551.  

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #80 on: May 31, 2014, 06:38:49 AM »
Very impressive, GSLS(SS)... Still not all cases are solvable... Look into my example DWG...

But thanks for reply, nice coding...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #81 on: May 31, 2014, 06:59:03 AM »
Another example...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

chlh_jd

  • Guest
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #82 on: June 02, 2014, 03:31:13 AM »
Ribar , thank you very much . :-)
I'v changed the routine's loop and some function to do better , but even found a no suit shape pl .
To run routine's , you must download the lisp file .
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test  (/ list-inters _Pedal suit-i used-si pnth add-item suit _closed
  2.                 _getclosed _getneighbor _getclosedinfo _closeditself _get_minz
  3.                 _getnoclosedpair _getnoclosdedpairinfo foo foo1 foo2 ;_loacal functions
  4.                 pl n i% sl bl rgl tl zl closed_n closed_il ;_through variables
  5.                 e i il rdl rnl rml a b c a1 b1 c1 p p0 p1 p2 p3 z sti bi fi ip0 ip1
  6.                 j0 j1 sil)
  7.   ;;  Find the ridge lines of sloped roof
  8.   ;;  V0.2  by GSLS(SS)  June 31 , 2014
  9.   ;;  
  10.   ;;------------------------------------local functions------------------------------;;
  11.   ;;
  12. ....)
  13.  

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #83 on: June 02, 2014, 06:04:01 AM »
Hi, chlh_jd... I must say I am very impressed... It almost work in every situation... I don't know why, by my "Another example" didn't finish like you showed on your animated GIF... I am on A2014 and didn't modify file I posted, just checked on the same polyline and it failed around start/end vertex... I've turned off debug mode, removed layer creation of ridge lines - uses current layer and done overkilling duplicate ridges through ALISP... And you showed on very complex example with revcloud some lack... Hope you'll solve this when you did it so good so far... I'll attach your lisp with those mods I mentioned (I don't want duplicate ridges)... Very grateful for this, thanks again GSLS(SS)...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

GDF

  • Water Moccasin
  • Posts: 2081
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #84 on: June 02, 2014, 10:59:49 AM »
pretty impressive
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #85 on: June 02, 2014, 02:37:35 PM »
chlh_jd, I've tried to improve, but I don't know if my attempt is good... Now my case is solved, but I don't know ab your (revcloud)... My attempt was pretty simple in comparison to your coding (made main sub-function - "start", and if it runs on error it restarts main function with little modified order of vertices - had to nil rgl variable)... So error should be printed, but solution should be made if my estimations were correct... Also made better formatting of code - never mind it's now bigger...

So long from me for now, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

chlh_jd

  • Guest
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #86 on: June 02, 2014, 08:59:42 PM »
Hi, chlh_jd... I must say I am very impressed... It almost work in every situation... I don't know why, by my "Another example" didn't finish like you showed on your animated GIF... I am on A2014 and didn't modify file I posted, just checked on the same polyline and it failed around start/end vertex... I've turned off debug mode, removed layer creation of ridge lines - uses current layer and done overkilling duplicate ridges through ALISP... And you showed on very complex example with revcloud some lack... Hope you'll solve this when you did it so good so far... I'll attach your lisp with those mods I mentioned (I don't want duplicate ridges)... Very grateful for this, thanks again GSLS(SS)...

M.R.
You are welcome .

chlh_jd, I've tried to improve, but I don't know if my attempt is good... Now my case is solved, but I don't know ab your (revcloud)... My attempt was pretty simple in comparison to your coding (made main sub-function - "start", and if it runs on error it restarts main function with little modified order of vertices - had to nil rgl variable)... So error should be printed, but solution should be made if my estimations were correct... Also made better formatting of code - never mind it's now bigger...

So long from me for now, M.R.
Ribar , Thank you for test , please post your error polygon for me , thanks .

I've catch the error you said , it's because of the accuracy of AutoCAD's VLIDE .
Even now the most Process of the Algorithm -- through bisector and axis from 2D , you can check every function with precision , and then found which is wrong .
Add change start point , shoud change each side to operate , and it can slove some error cause by precision .  In my opinion , change every point's coordinates into according the centroid , and then transform them back after get the result , this method will be some better .

It  can  be easy modified into support 3D method , because it has Z list , like building each side  region and then union them . Enjoy .

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #87 on: June 03, 2014, 12:31:13 AM »
Ribar , Thank you for test , please post your error polygon for me , thanks .

Here is it - see attachment...

[EDIT] : Also if you plan to use my modified version of your code, change this :
Code: [Select]
          (princ "\n ***Error*** : ...")
          (setq rgl nil)
          (setq err (1+ err))
          (setq pl (cons (last pl) (reverse (cdr (reverse pl)))))
          (if (eq err 1) (start pl))
To this, so it can exchange all points and attempt to solve for each combination :
Code: [Select]
          (princ "\n ***Error*** : ...")
          (setq rgl nil)
          (setq err (1+ err))
          (setq pl (cons (last pl) (reverse (cdr (reverse pl)))))
          (if (< err n) (start pl))

M.R.
« Last Edit: June 03, 2014, 03:39:33 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

chlh_jd

  • Guest
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #88 on: June 03, 2014, 05:28:01 AM »
Ribar , this one has fix the bug in the case of the dwg you post
The first closed side vectexs , must determin in the other  inzoneside triangle .
Code: [Select]
    ;; if the point in the triangle {pa pb [i0~3]} which construct by the inzone side {pa pb}
    ;;                        and it's bisector rays inters with line {p p1} or line {p p2} 
    ;; SCH. of Invalid ray-inters of side {p1 p2}         
    ;;         p2___________p1                     
    ;;           \i1       /                       
    ;;         /\      /             
    ;;          /   \\   /               
    ;;       bi_a  /      \ \/               
    ;;        |  /         \ /\bi_b           
    ;;         |/            P   \             
    ;;         pa-------------------pb                     
« Last Edit: June 03, 2014, 05:37:18 AM by chlh_jd »

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: ==={Challenge}===Find the ridge lines of sloped roof
« Reply #89 on: June 03, 2014, 07:18:10 AM »
Congratulations, GSLS... What is the problem then with revcloud? I also have issues with arced polylines... But solving my posted DWG, I hope situation is much better... chlh_jd, do I have to use my attached version to solve posted DWG "Another example" or do you also have some better approach? I'll attach my version of implemented your new solution - this is what I use finally for now... Thanks again... M.R.

[EDIT] : Attached one more case...
[EDIT] : LSP file reattached so that now if solution was found no need for overkill of ridges...
(4 downloads of old version)
« Last Edit: June 03, 2014, 05:52:35 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube