Author Topic: Geometry problem: length of segments knowing the area, perimeter and width  (Read 8385 times)

0 Members and 1 Guest are viewing this topic.

GP

  • Newt
  • Posts: 83
  • Vercelli, Italy
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #30 on: November 22, 2014, 07:13:34 PM »
My attempt  :-)


owenwengerd

  • Bull Frog
  • Posts: 451
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #31 on: November 22, 2014, 07:41:19 PM »
I think it would be best to withhold your solutions until Marco has tried on his own, else you deny him the opportunity to learn from the experience.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #32 on: November 23, 2014, 02:40:20 PM »
I think it would be best to withhold your solutions until Marco has tried on his own, else you deny him the opportunity to learn from the experience.
you're right, I was trying but I would never have done such a thing!

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #33 on: November 23, 2014, 02:47:50 PM »
My attempt  :)
this is not an attempt but it is much more  :o      tomorrow I'll try as soon as possible...
 

ribarm

  • Gator
  • Posts: 3255
  • Marko Ribar, architect
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #34 on: November 23, 2014, 04:12:46 PM »
My attempt is like Owen described in a few steps... No need for using additional routine...
Minimally tested...

Code: [Select]
(defun c:STL-all ( / vk_IsPointInside chk2ptcitouch ss le tl i lw ar ll ptlst ptlstn d1 d2 d3 d4 mitter )

  (defun vk_IsPointInside ( Point PointsList / PY P1Y P2Y )
  ; works with polygons only, i.e. if (equal (car PointsList) (last PointsList))
    (if (cdr PointsList)
      (/= (and (or (and (<= (setq PY  (cadr Point)
                                  P2Y (cadadr PointsList)
                                  P1Y (cadar PointsList)
                            )
                            PY
                        )
                        (< PY P2Y)
                    )
                    (and (> P1Y PY) (>= PY P2Y))
                )
                (> (car Point)
                    (+ (* (/ (- PY P1Y) (- P2Y P1Y))
                          (- (caadr PointsList) (caar PointsList))
                       )
                       (caar PointsList)
                    )
                )
          )
          (vk_IsPointInside Point (cdr PointsList))
      )
    )
  )

  (defun chk2ptcitouch ( p r lw / p1 p2 p3 p4 chk ) (vl-load-com)
    (setq p1 (mapcar '+ (list (car p) (cadr p) 0.0) (list r 0.0 0.0)))
    (setq p2 (mapcar '+ (list (car p) (cadr p) 0.0) (list (- r) 0.0 0.0)))
    (setq p3 (mapcar '+ (list (car p) (cadr p) 0.0) (list 0.0 r 0.0)))
    (setq p4 (mapcar '+ (list (car p) (cadr p) 0.0) (list 0.0 (- r) 0.0)))
    (setq chk 0)
    (if (vlax-curve-getparamatpoint lw p1) (setq chk (1+ chk)))
    (if (vlax-curve-getparamatpoint lw p2) (setq chk (1+ chk)))
    (if (vlax-curve-getparamatpoint lw p3) (setq chk (1+ chk)))
    (if (vlax-curve-getparamatpoint lw p4) (setq chk (1+ chk)))
    (if (eq chk 2) T nil)
  )
 
  (prompt "\nSelect all square-tube LWPOLYLINES")
  (setq ss (ssget (list '(0 . "LWPOLYLINE") '(-4 . "<or") '(70 . 1) '(70 . 129) '(-4 . "or>")
                  )
           )
  )
  (while (null ss)
    (prompt
      "\nEmpty sel.set... Please try selecting all square-tube LWPOLYLINES again..."
    )
    (setq ss (ssget (list '(0 . "LWPOLYLINE") '(-4 . "<or") '(70 . 1) '(70 . 129) '(-4 . "or>")
                    )
             )
    )
  )
  (initget 7)
  (setq le (getdist "\nPick or specify conduit width : "))
  (setq tl 0.0)
  (setq d1 (list le le))
  (setq d2 (list (- le) le))
  (setq d3 (list le (- le)))
  (setq d4 (list (- le) (- le)))
  (repeat (setq i (sslength ss))
    (setq lw (ssname ss (setq i (1- i))))
    (command "_.AREA" "_O" lw)
    (setq ar (getvar 'area))
    (setq ll (/ ar le))
    (setq ptlst (mapcar 'cdr
                        (vl-remove-if-not
                          '(lambda ( x ) (eq (car x) 10))
                          (entget lw)
                        )
                )
    )
    (setq ptlstn (reverse (cons (car ptlst) (reverse ptlst))))
    (setq mitter 0)
    (foreach pt ptlst
      (if
        (cond
          ( (and
              (vl-some '(lambda ( x ) (equal (mapcar '+ pt d1) x 1e-5)) ptlst)
              (vk_IsPointInside (mapcar '+ pt (mapcar '/ d1 (list 2.0 2.0))) ptlstn)
              (chk2ptcitouch (mapcar '+ pt (mapcar '/ d1 (list 2.0 2.0))) (/ le 2) lw)
            )
            T
          )
          ( (and
              (vl-some '(lambda ( x ) (equal (mapcar '+ pt d2) x 1e-5)) ptlst)
              (vk_IsPointInside (mapcar '+ pt (mapcar '/ d2 (list 2.0 2.0))) ptlstn)
              (chk2ptcitouch (mapcar '+ pt (mapcar '/ d2 (list 2.0 2.0))) (/ le 2) lw)
            )
            T
          )
          ( (and
              (vl-some '(lambda ( x ) (equal (mapcar '+ pt d3) x 1e-5)) ptlst)
              (vk_IsPointInside (mapcar '+ pt (mapcar '/ d3 (list 2.0 2.0))) ptlstn)
              (chk2ptcitouch (mapcar '+ pt (mapcar '/ d3 (list 2.0 2.0))) (/ le 2) lw)
            )
            T
          )
          ( (and
              (vl-some '(lambda ( x ) (equal (mapcar '+ pt d4) x 1e-5)) ptlst)
              (vk_IsPointInside (mapcar '+ pt (mapcar '/ d4 (list 2.0 2.0))) ptlstn)
              (chk2ptcitouch (mapcar '+ pt (mapcar '/ d4 (list 2.0 2.0))) (/ le 2) lw)
            )
            T
          )
          ( T nil )
        )
        (setq mitter (1+ mitter))
      )
    )
    (setq tl (+ tl (+ ll (* le (/ mitter 2)))))
  )
  (prompt
    "\nTotal length of all square-tube LWPOLYLINES is : "
  )
  (princ (rtos tl 2 50))
  (princ)
)

Your turn for testing...
Kr. M.R.
« Last Edit: November 26, 2014, 01:42:17 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #35 on: November 24, 2014, 12:17:43 PM »
My attempt  :)
Very well, the program is slow because it performs a very complex calculation, I have to review something for use with polylines with "straight" vertices and with width of the conduit is not perfect (249.9999).
Grazie ancora!
My attempt is like Owen described in a few steps... No need for using additional routine...
Minimally tested...
...
Your turn for testing...
Kr. M.R.
This is very fast, I have to review something for use with polylines with "straight" vertices and for lenth of the conduit equal to width (see my dwg).
Grazie mille for your time.

ribarm

  • Gator
  • Posts: 3255
  • Marko Ribar, architect
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #36 on: November 26, 2014, 01:44:25 PM »
Hi Marc'... I've changed my code to include cases when segment lengths are the same as conduit width... Try my code updated above and test it to see if everything's OK...

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

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #37 on: November 26, 2014, 03:12:46 PM »
Hi Marc'... I've changed my code to include cases when segment lengths are the same as conduit width... Try my code updated above and test it to see if everything's OK...

Kr. M.R.
Grazie ancora, I need few days to test, now I have new problems to solve...
Ciao.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Geometry problem: length of segments knowing the area, perimeter and width
« Reply #38 on: December 09, 2014, 11:04:16 AM »
Hi Marc'... I've changed my code to include cases when segment lengths are the same as conduit width... Try my code updated above and test it to see if everything's OK...

Kr. M.R.
Hi Marko, with a "little" delay I finally managed to try fully your solution and it works perfectly. I just have to add the option to have width of the conduit is not accurate (249.9999).
Thanks again.     Marco