Author Topic: Checking parallel lines  (Read 3974 times)

0 Members and 1 Guest are viewing this topic.

subbup

  • Guest
Checking parallel lines
« on: June 10, 2004, 03:07:46 AM »
Hello all, :D

Thanks in advance.
Could anyone tell how  to check two polylines are parallel or not.both are different length's. if any ready made code available let me know. :idea:


[/b]

SMadsen

  • Guest
Checking parallel lines
« Reply #1 on: June 10, 2004, 04:36:29 AM »
Subbup, hello and welcome.

If you had requested tips on how to check for parallel lines, it would not be a problem but some questions arises for parallel polyline.
Should it check all segments or only the ones directly at the pickpoints? Should it include arched segments? And so on...

I have a routine to check for parallel lines that I use all the time but I guess one could easily be written for polylines - given some guidelines for what it should be able to do.

subbup

  • Guest
Checking parallel lines
« Reply #2 on: June 10, 2004, 06:19:08 AM »
SMadsen,
Thanks, :)
It Should check all segments, there is no arc's in the polyline's.
I want to place circle's at those vertex's which does't maintain that specified distance.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Checking parallel lines
« Reply #3 on: June 10, 2004, 07:36:52 AM »
Stig,

Just curious, did you use the INTERS function to test for parallel lines?

CAB
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.

SMadsen

  • Guest
Checking parallel lines
« Reply #4 on: June 10, 2004, 08:39:17 AM »
CAB, yes

SMadsen

  • Guest
Checking parallel lines
« Reply #5 on: June 11, 2004, 07:17:27 AM »
Subbup, here's the parallel lines routine that I use (sorry about the broken links to the lisp's)

Code: [Select]
;;; Parallel.lsp                                          *
;;; Check for parallel lines. If lines are not parallel,  *
;;; then report information about intersection point.     *
;;; 2000, Stig Madsen
;;; Rev. June 2004

(defun validate (ent enttypes / entl)
  (and ent
    (cond ((member (cdr (assoc 0 (setq entl (entget (car ent))))) enttypes)
           (cond ((= (type (car (last ent))) 'ENAME) (princ " *subentity*"))))
          ((princ "\nWrong entity type"))
    )
  )
  entl
)

(defun averageDist (plst pt)
  (/ (apply '+ (mapcar (function (lambda (p) (distance p pt))) plst))
     (length plst)
  )
)

(defun C:PAR (/ ent1 ent2 p1 p2 p3 p4 ang dist pt ptd ptf)
  (setvar "ERRNO" 0)
  (while (and
      (not (setq ent1 (validate (nentsel "\nSelect first line: ") '("LINE"))))
      (/= (getvar "ERRNO") 52))
  )
  (while (and ent1
      (not (setq ent2 (validate (nentsel "\nSelect second line: ") '("LINE"))))
      (/= (getvar "ERRNO") 52))
  )
  (cond (ent2
         (mapcar (function (lambda (p dxf e)(set p (cdr (assoc dxf e)))))
                 '(p1 p2 p3 p4) '(10 11 10 11) (list ent1 ent1 ent2 ent2))
         (setq ang (- (angle p1 p2) (angle p3 p4))
               ptf (inters p1 p2 p3 p4)
               ptd (inters p1 p2 p3 p4 nil))
         (and (zerop (getvar "WORLDUCS"))
              (mapcar (function (lambda (p) (and (eval p)
                                     (set p (trans (eval p) 0 1)))))
                      '(p1 p2 p3 p4 ptf ptd))
         )

         (cond (ptf
            (mapcar 'princ
                    (list "\nObjects intersect physically: "
                          (car ptf) "," (cadr ptf) "," (caddr ptf)
                          (if (zerop (getvar "WORLDUCS"))
                            " (UCS)" " (WCS)")
                          "\nAngle between objects: " (angtos ang)))
           )
           (ptd
            (setq dist  (averageDist (list p1 p2 p3 p4) ptd))
            (mapcar 'princ
              (list "\nObjects intersect at distant point: "
                (car ptd) "," (cadr ptd) "," (caddr ptd)
                (if (zerop (getvar "WORLDUCS")) " (UCS)" " (WCS)")
                "\nApprox. "  dist " units away from objects."
                "\nAngle between objects:  " (angtos ang))
            )
           )
           (t (princ "\nObjects are parallel"))
         )
        )
  )
  (princ)
)

subbup

  • Guest
Checking parallel lines
« Reply #6 on: June 11, 2004, 09:13:05 AM »
Stig,

thanks for the lisp, but mine all are polylines.How to deal with that?

SMadsen

  • Guest
Checking parallel lines
« Reply #7 on: June 12, 2004, 08:22:39 AM »
Well, notice the INTERS function(s) in the code above? Assuming you are dealing with 2D poly's, I would suggest that you make a list of vertices for the entities you need to check and run INTERS for each and every segment (1 segment = 2 adjacent vertices).

To get vertices from an LWPOLYLINE, you could use a simple loop:

Code: [Select]
(defun getVerts (ent / entl vlist)
  (foreach n (setq entl (entget ent))
    (if (= (car n) 10)
      (setq vlist (cons (cdr (assoc 10 entl)) vlist))
  ))
  vlist)


Once having two lists of vertices, it won't be hard to run INTERS on segments and report parallelism or lack thereof.

The hard part will be the decisions to make when poly's have different number of vertices, when direction is important and when coordinate translation is an issue.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Checking parallel lines
« Reply #8 on: June 12, 2004, 09:12:24 AM »
When I think about it comparing two plines with straight segments, most
segments will not be parallel with most segments of the other pline.
In fact parallel segments might be rare.

I would do it like this:

Code: [Select]
Get pline a
get pline b
get pline vertex list from a
get pline vertex list from a
Loop a vertex list
  loop b vertex list
    compare segments
    report results
  end loop b
end loop a


not sure how meaningful the report of parallel segments would be
as they would have to reference the segments as 1 2 3 or A B C

CAB
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.