Outermost line

Outermost line

rajeshpatnaik2001
Advocate Advocate
2,114 Views
25 Replies
Message 1 of 26

Outermost line

rajeshpatnaik2001
Advocate
Advocate

I need to find the outermost lines (example: red lines in the snapshot below )from a bunch of lines. Any help in this regards will be highly appreciated. Thanks.

 

Capture.PNG

0 Likes
Accepted solutions (1)
2,115 Views
25 Replies
Replies (25)
Message 21 of 26

john.uhden
Mentor
Mentor

That's strange.  It appears to be working, but the line from p1 to p2 seems to be roughly perpendicular to the selection set.  And I am not understanding the use of d1min and d2min (being minimums instead of maximums).  One would think you are looking for the innermost lines.  You have succeeded in making me feel dumb.

John F. Uhden

0 Likes
Message 22 of 26

marko_ribar
Advisor
Advisor

Look John, I'll try to explain...

 

In my situation, I am searching for points p1 and p2 that are on imaginary line on the both sides from middle point perpendicular to average angle of lines... Then points of intersections are found from every middle point of line to perpendicular direction of p1 p2 on that imaginary line p1 p2 - that means points of intersections are crossing p1 p2 and imaginary parallel line to average angle of lines from middle point of each line until that line intersects p1 p2... If you than look to those points of intersections they are distributed along imaginary line p1 p2 and the solution to this task from my point of view was to look to the most closer point to point p1 from one side and the most closer point to point p2 from the other side of imaginary line p1 p2... So instead of looking to furthest distances from middle of points, I am doing just the opposite assuming that p1 and p2 are very far from all reference lines that are subject of interest... When closest point (minimum distance) is found then that intersection point is solution to reference line that is corresponding to outemost line from middle point from one side - side of p1 and outermost line is the closest to point p1 and similar this refers the same to other side - point p2...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 23 of 26

marko_ribar
Advisor
Advisor

Not sure about this one, but I tried to correct my firstly posted (avgang) sub function...

 

(defun avgang ( anglst / a pl p )
  (while (setq a (car anglst))
    (setq anglst (cdr anglst))
    (if (<= pi a (* 2 pi))
      (setq a (- a pi))
    )
    (setq pl (cons (list (sin a) (cos a)) pl))
  )
  (setq p (list (/ (apply (function +) (mapcar (function car) pl)) (length pl)) (/ (apply (function +) (mapcar (function cadr) pl)) (length pl))))
  (if (equal p (list 0.0 0.0) 0.05)
    0.0
    (atan (car p) (cadr p))
  )
)

;(avgang (list (+ 0.0 (/ pi 100)) (- (* 2 pi) (/ pi 100)) (+ pi (/ pi 100)) (- pi (/ pi 100))))
; passed as 0.0
;(avgang (list (+ (/ pi 2) (/ pi 100)) (- (/ pi 2) (/ pi 100)) (+ (* 1.5 pi) (/ pi 100)) (- (* 1.5 pi) (/ pi 100))))
; passed as 1.5708
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 24 of 26

john.uhden
Mentor
Mentor

Aha!  That makes perfect sense!  I'll have to stop looking through binoculars from the wrong end.

BTW, in recent years a number of red-tailed hawks have made their home in my neighborhood.  Very impressive creatures, especially when seen through binoculars held in the correct direction.  With the property next door having been deforested to make way for new construction, they have found my gigantic pine tree a regular place to perch.  Of course the blue jays have no fear and attack them fiercely, even though they are about 1/6 the size.

John F. Uhden

0 Likes
Message 25 of 26

phanaem
Collaborator
Collaborator

Kent

 

Your function is OK, with correct results, but there must be a purely mathematical solution.

 

Beside the solution in my last post, here is an alternative:

 

(defun average_angle (lst / u)
  (setq u (car lst)
        lst (mapcar
              '(lambda (a)
                 (if
                   (and
                     (equal (sin a) (sin u) 1)
                     (equal (cos a) (cos u) 1)
                   )
                   a
                   (rem (+ a pi) (* 2 pi))
                 )
               )
               lst
           )
  )
  (/ (apply '+ lst) (length lst))
)

And here is a test function

 

(defun c:test ( / m2p ss i n e p1 p2 a l u p)
  (defun m2p (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) a b))
  (if
    (setq ss (ssget '((0 . "LINE"))))
    (progn
      (repeat (setq i (sslength ss) n i)
        (setq i  (1- i)
              e  (entget (ssname ss i))
              p1 (cdr (assoc 10 e))
              p2 (cdr (assoc 11 e))
              a  (cons (angle p1 p2) a)
              l (cons (m2p p1 p2) l)
        )
      )
      (setq a (average_angle a)
            u (list (cos a) (sin a) 0.0)
            p (mapcar '/ (apply 'mapcar (cons '+ l)) (list n n n))
            )
      (entmakex
        (list
          '(0 . "XLINE")
          '(100 . "AcDbEntity")
          '(100 . "AcDbXline")
          (cons 10 p)
          (cons 11 u)
        )
      )
    )
  )
  (princ)
)
0 Likes
Message 26 of 26

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

Here's a brute-force ... way ....

 

It Copies each Line other than the first one ....


Here's the equivalent [I think] in a non-brute-force calculation-only way, not involving Copying or any (command) functions and therefore no concern for OSMODE:

 

(setq
  ss (ssget '((0 . "LINE")))
  qua (sslength ss)
  start0 (vlax-curve-getStartPoint (setq line1 (ssname ss 0)))
  sumend (setq end0 (vlax-curve-getEndPoint line1))
  len0 (distance start0 end0)
); setq
(repeat (1- (setq n qua))
  (setq
    obj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
    len1 (vla-get-Length obj)
    ang1 (vla-get-Angle obj)
  ); setq
  (if
    (> (distance end0 (setq end1 (polar start0 ang1 len1))) len0); copy virtually -- aims away?
    (setq end1 (polar start0 (+ ang1 pi) len1)); then -- spin it virtually
  ); if
  (setq sumend (mapcar '+ sumend end1))
); repeat
(setq angavg (angle start0 (mapcar '(lambda (c) (/ c qua)) sumend)))
  ; angle from common start point to averaged virtual endpoint

 

Kent Cooper, AIA
0 Likes