Author Topic: Help with intersection  (Read 5874 times)

0 Members and 1 Guest are viewing this topic.

velasquez

  • Newt
  • Posts: 195
Help with intersection
« on: July 15, 2015, 10:09:43 PM »
I have a list with two points that intersect one polyline, how to find the point of intersection?
I can not work with vla-intersectwith because I only have one entity.
« Last Edit: July 15, 2015, 10:49:35 PM by velasquez »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help with intersection
« Reply #1 on: July 15, 2015, 11:03:39 PM »
Create a temporary entity.
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.

velasquez

  • Newt
  • Posts: 195
Re: Help with intersection
« Reply #2 on: July 16, 2015, 12:18:43 AM »
I have a list with two points that intersect one polyline, how to find the point of intersection?
I can not work with vla-intersectwith because I only have one entity.

Hello Cab,
This is my problem that happens in a while.
I want to avoid the creation of many temporary entities.
Thanks

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Help with intersection
« Reply #3 on: July 16, 2015, 12:58:11 AM »
You can step through the vertices of the polyline, and use the built in Lisp function 'inters' with the four points ( two from the polyline, per segment, and the two you show as yellow in your image ) you have.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help with intersection
« Reply #4 on: July 16, 2015, 01:38:52 AM »
Or you could do something like this :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:doit (/ catchit intersectionpoint obj1 p1 p2 templine)
  2.    ;; Codehimbelonga kdub 2015/07/16
  3.    ;; Proof of concept code
  4.  
  5.    (if (and
  6.           (setq p1 (getpoint "Select First Point"))
  7.           (setq p2 (getpoint p1 "Select Second Point"))
  8.  
  9.           (setq obj1 (entsel))
  10.           (setq obj1 (car obj1))
  11.  
  12.           (setq tempLine
  13.                   (vla-addline
  14.                      (kdub:activespace)
  15.                      (vlax-3d-point p1)
  16.                      (vlax-3d-point p2)
  17.                   )
  18.           )
  19.        )
  20.       (setq catchit (vl-catch-all-apply
  21.                        'vla-intersectwith
  22.                        (list tempLine
  23.                              (vlax-ename->vla-object obj1)
  24.                              acextendboth
  25.                        )
  26.                     )
  27.       )
  28.    )
  29.    (if tempLine
  30.       (vla-delete tempLine)
  31.    )
  32.    (if (and catchit (not (vl-catch-all-error-p catchit)))
  33.                 (setq IntersectionPoint (kdub:lisp-value catchit))
  34.              )
  35.       )
  36.       (alert "Oooops")
  37.    )
  38.  
  39.  
  40.    (princ)
  41. )
  42.  

LIBRARY STUFF
Code - Auto/Visual Lisp: [Select]
  1. ;; (setq *:acapp nil *:activedoc nil *:modelspace nil *:paperspace nil)
  2. ;;;; IAcadApplication Object
  3. (or *:acapp (setq *:acapp (vlax-get-acad-object)))
  4.  
  5. ;;;; IAcadDocument Object
  6. (or *:activedoc
  7.     (setq *:activedoc (vla-get-activedocument *:acapp))
  8. )
  9.  
  10. ;;;; IAcadModelSpace Object
  11. (or *:modelspace
  12.     (setq *:modelspace (vla-get-modelspace *:activedoc))
  13. )
  14.  
  15. ;;;; IAcadPaperSpace Object
  16. (or *:paperspace
  17.     (setq *:paperspace (vla-get-paperspace *:activedoc))
  18. )
  19.  
  20. ;;--------------------------------------------------------------
  21. ;;--------------------------------------------------------------
  22. (defun kdub:activespace ()
  23.    (if (= acmodelspace (vla-get-activespace *:activedoc))
  24.       *:modelspace
  25.       (if (= :vlax-true (vla-get-mspace *:activedoc))
  26.          *:modelspace
  27.          (vla-get-paperspace *:activedoc)
  28.       )
  29.    )
  30. )
  31. ;;--------------------------------------------------------------
  32. ;;; lisp-value : Author : Vladimir Nesterovsky 2002
  33. (defun kdub:lisp-value (val)
  34.    (cond
  35.       ((= (type val) 'variant) (kdub:lisp-value (variant-value val)))
  36.       ((= (type val) 'safearray)
  37.        (mapcar 'kdub:lisp-value (safearray-value val))
  38.       )
  39.       (t val)
  40.    )
  41. )
  42. ;;--------------------------------------------------------------
  43.  
« Last Edit: July 16, 2015, 05:00:29 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Help with intersection
« Reply #5 on: July 16, 2015, 04:10:50 AM »
@ Kerry: Can you explain this:
Code - Auto/Visual Lisp: [Select]
  1. ;;;; IAcadApplication Object
Shouldn't there be a setq somewhere?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help with intersection
« Reply #6 on: July 16, 2015, 04:57:22 AM »
@ Kerry: Can you explain this:
Code - Auto/Visual Lisp: [Select]
  1. ;;;; IAcadApplication Object
Shouldn't there be a setq somewhere?

Yes there should.
I usually do the assignment  to a protected variable ... mucked up the edit for here.

Will fix shortly ...
Thanks for the sharp eye.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Help with intersection
« Reply #7 on: July 16, 2015, 07:48:53 AM »
You can step through the vertices of the polyline, and use the built in Lisp function 'inters' with the four points ( two from the polyline, per segment, and the two you show as yellow in your image ) you have.

1+

Here's an example:
http://www.theswamp.org/index.php?topic=43630.msg489026#msg489026

velasquez

  • Newt
  • Posts: 195
Re: Help with intersection
« Reply #8 on: July 17, 2015, 02:04:40 PM »
You can step through the vertices of the polyline, and use the built in Lisp function 'inters' with the four points ( two from the polyline, per segment, and the two you show as yellow in your image ) you have.
Hello and thank you Lee,
I do not have a straight polyline the points that I have not intersect.
I need to work with (inters p1 p2 p3p4 nil) to extend.
I'll try the suggestion of T.Willey to go through the vertices of the polyline looking for the intersection.
Do you have any suggestion?...

velasquez

  • Newt
  • Posts: 195
Re: Help with intersection
« Reply #9 on: July 17, 2015, 02:08:06 PM »
Code: [Select]
[quote author=Kerry link=topic=49763.msg549263#msg549263 date=1437025132]
Or you could do something like this :

Thank you Kerry,
But I can not create a temporary line.

   

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help with intersection
« Reply #10 on: July 17, 2015, 04:50:10 PM »
You can not
or you will not ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

velasquez

  • Newt
  • Posts: 195
Re: Help with intersection
« Reply #11 on: July 17, 2015, 05:02:54 PM »
You can not
or you will not ?
Hello Kerry,
I do not informed well, I should not interrupt the work of a function to create a temporary entity and then delete it, as it may happen thousands of times. I already have a polyline selected in beginning the work of a function.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Help with intersection
« Reply #12 on: July 17, 2015, 05:20:25 PM »
You can not
or you will not ?
Hello Kerry,
I do not informed well, I should not interrupt the work of a function to create a temporary entity and then delete it, as it may happen thousands of times. I already have a polyline selected in beginning the work of a function.

You don't need to interrupt anything or do anything manually.

Have you tried the code or looked at how it works ??

The line is drawn and erased when finished by the program ... I doubt you will actually ever see it.

The code is just proof of concept to demonstrate the functionality. I doesn't matter if you select the points and line or if they are provided programmatically ; the methodology still works.

For production code I'd produce a standalone function that takes the pline object and the 2 points as parameters and returns either the intersection point of nil, as applicable. This way it can be called from either an interactive or programmatic situation.

Regards,
 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

velasquez

  • Newt
  • Posts: 195
Re: Help with intersection
« Reply #13 on: July 17, 2015, 06:31:30 PM »
You can not
or you will not ?
Hello Kerry,
I do not informed well, I should not interrupt the work of a function to create a temporary entity and then delete it, as it may happen thousands of times. I already have a polyline selected in beginning the work of a function.

You don't need to interrupt anything or do anything manually.

Have you tried the code or looked at how it works ??

The line is drawn and erased when finished by the program ... I doubt you will actually ever see it.

The code is just proof of concept to demonstrate the functionality. I doesn't matter if you select the points and line or if they are provided programmatically ; the methodology still works.

For production code I'd produce a standalone function that takes the pline object and the 2 points as parameters and returns either the intersection point of nil, as applicable. This way it can be called from either an interactive or programmatic situation.

Regards,
 

Many thanks Kerry,
Your code works perfectly.



mianbaoche

  • Guest
Re: Help with intersection
« Reply #14 on: July 18, 2015, 08:57:22 AM »


   (defun c:tt()
   (princ "\nPlease select LWPOLYLINE")(setq en (car(entsel)))
   (princ "\nPlease selectLINE")(setq e1(entget (car(entsel))))
  (foreach a (_polyinters en (cdr (assoc 10 e1)) (cdr (assoc 11 e1)))  (entmakex (list (cons 0 "CIRCLE")(cons 10 a)(cons 40 40))))
 (princ) )

(defun _polyinters ( en p1 p2 / vl l ang)
    (setq en (entget en)
          vl (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) en))
          l (distance (apply 'mapcar (cons 'min vl)) (apply 'mapcar (cons 'max vl)))
     ang (angle p1 p2)
     )
    (vl-remove-if 'null
        (mapcar '(lambda ( p3 p4 ) (inters (polar p1 ang l) (polar p2 (+ ang pi) l) p3 p4))
            vl
            (if (= 1 (logand 1 (cdr (assoc 70 en))))
                (append (cdr vl) (list (car vl)))
                (cdr vl)
            )
        )
    )
)
« Last Edit: July 18, 2015, 11:35:14 PM by mianbaoche »