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.
@ Kerry: Can you explain this:Code - Auto/Visual Lisp: [Select]Shouldn't there be a setq somewhere?
;;;; IAcadApplication Object
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.
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?...
[quote author=Kerry link=topic=49763.msg549263#msg549263 date=1437025132]
Or you could do something like this :
You can notHello Kerry,
or you will not ?
You can notHello Kerry,
or you will not ?
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 can notHello Kerry,
or you will not ?
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,
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
;; Based on Lee Mac codes
;; Args -> <LWPolyline-entity> <Entity name: 7ffffc6cc40> <point1>
;; (setq JoyPT (JoyFindInters en ptbase)) ==> (792.205 374.229)
;;
(defun JoyFindInters (en JoyPtBase / LM:ProjectPointToLine GetPointsInBoundingBox _polyinters JoyPointList JoyPtAux)
;; Lee Mac
;; Projects pt onto the line defined by p1,p2
(defun LM:ProjectPointToLine (pt p1 p2 / nm)
(setq nm (mapcar '- p2 p1)
p1 (trans p1 0 nm)
pt (trans pt 0 nm)
) ;_ fim de setq
(trans (list (car p1) (cadr p1) (caddr pt)) nm 0)
) ;_ fim de defun
;;;
;; Bounding Box - Lee Mac
;; List with top left point top right point
(defun GetPointsInBoundingBox (/ a b lst)
(vla-getboundingbox
(vlax-ename->vla-object en)
'a
'b
) ;_ fim de vla-getboundingbox
(setq lst (mapcar 'vlax-safearray->list (list a b)))
(mapcar '(lambda (a) (mapcar '(lambda (b) ((eval b) lst)) a))
'((caar cadadr) (caadr cadadr))
) ;_ fim de mapcar
) ;_ fim de defun
;;;
;;;Lee Mac's suggestion
(defun _polyinters (/ vl)
(setq en (entget en)
vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) en))
) ;_ fim de setq
(vl-remove-if
'null
(mapcar '(lambda (p3 p4) (inters JoyPtBase JoyPtAux p3 p4))
vl
(if (= 1 (logand 1 (cdr (assoc 70 en))))
(append (cdr vl) (list (car vl)))
(cdr vl)
) ;_ fim de if
) ;_ fim de mapcar
) ;_ fim de vl-remove-if
) ;_ fim de defun
(alert "cheguei")
(setq JoyPointList (GetPointsInBoundingBox)
JoyPtAux (LM:ProjectPointToLine JoyPtBase (car JoyPointList) (cadr JoyPointList))
) ;_ fim de setq
;;;
(car (_polyinters))
) ;_ fim de defun
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
@ mianbaoche:Velasquez what you are doing is similar to what mianbaoche proposed. There is no need for your two nested functions.
... The (inters) function has an optional 5th argument:
http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69d4.htm
If the onseg argument is present and is nil, inters returns the point where the lines intersect, even if that point is off the end of one or both of the lines. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil. The inters function returns nil if the two lines do not intersect.
@ mianbaoche:Velasquez what you are doing is similar to what mianbaoche proposed. There is no need for your two nested functions.
... The (inters) function has an optional 5th argument:
http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69d4.htmQuote from: http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69d4.htmIf the onseg argument is present and is nil, inters returns the point where the lines intersect, even if that point is off the end of one or both of the lines. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil. The inters function returns nil if the two lines do not intersect.
@ mianbaoche:Velasquez what you are doing is similar to what mianbaoche proposed. There is no need for your two nested functions.
... The (inters) function has an optional 5th argument:
http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69d4.htmQuote from: http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69d4.htmIf the onseg argument is present and is nil, inters returns the point where the lines intersect, even if that point is off the end of one or both of the lines. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil. The inters function returns nil if the two lines do not intersect.
Hello Roy,The solution that I would use:
Working this way the point can occur outside the polyline for the search loop. This should not happen to me.
(equal ptFound (vlax-curve-getclosestpointto polylineObj ptFound T) 1e-8)
Thank you Roy,Hello Roy,The solution that I would use:
Working this way the point can occur outside the polyline for the search loop. This should not happen to me.
Call the (inters) function with nil as the 5th argument.
If an intersection is found check the intersection with:Code: [Select](equal ptFound (vlax-curve-getclosestpointto polylineObj ptFound T) 1e-8)
Hello Roy,The solution that I would use:
Working this way the point can occur outside the polyline for the search loop. This should not happen to me.
Call the (inters) function with nil as the 5th argument.
If an intersection is found check the intersection with:Code: [Select](equal ptFound (vlax-curve-getclosestpointto polylineObj ptFound T) 1e-8)
;;;List of polyline segments in 3D points
;;;Args <LWPolyline-entity> Index of the first vertex
;;;(f en 0))
(defun f (en i)
(if (<= i (vlax-curve-getendparam en))
(cons
(vlax-curve-getpointatparam en i)
(f en (1+ i))
) ;_ fim de cons
) ;_ fim de if
) ;_ fim de defun
;;;Args -> <LWPolyline-entity> <Entity name: 7ffffc6cc40> <point1> <point2>
;;; (setq IntersPt (JoyFindIntersec en pt1 pt2)) ==> (792.205 374.229)
(defun JoyFindIntersec (JoyEnt p1 p2 / JoyPlSegments)
;;;
(vl-load-com)
;;;
;;;List of segments
(setq JoySegments (f JoyEnt 0))
;;;Creates a list of possible intersections
(setq JoyListPts
(vl-remove-if
'null
(mapcar '(lambda (p3 p4) (inters p1 p2 p3 p4 nil))
lista
(cdr lista)
) ;_ fim de mapcar
) ;_ fim de vl-remove-if
) ;_ fim de setq
;;;
;;;Checks the position of the point in polyline
(car (vl-remove-if
'null
(mapcar '(lambda (x)
(if (equal x (vlax-curve-getclosestpointto JoyEnt x t) 1e-8)
x
) ;_ fim de if
) ;_ fim de lambda
JoyListPts
) ;_ fim de mapcar
) ;_ fim de vl-remove-if
) ;_ fim de car"