Costinbos77 Posted March 20, 2013 Posted March 20, 2013 (edited) Hi there, how to calculate points of intersection (i1, i2, i3, ...), including some vertical lines and polyline, as in the image below: Lines 1i1, 2i2, 3i3 does not exist . ; j = 1 to 3 ... i[j] = (mapcar '+ '(0 100) [j] )) Any ideas ? Edited March 21, 2013 by Costinbos77 Quote
Lee Mac Posted March 20, 2013 Posted March 20, 2013 This should point you in the right direction: Intersection Functions Quote
Tharwat Posted March 20, 2013 Posted March 20, 2013 This should work for lines only .. (defun c:Test (/ _Ang s e sad ss i sn ent) (defun _Ang (e) (angle (cdr (assoc 10 e)) (cdr (assoc 11 e)))) (if (and (setq ss (ssget "_X" '((0 . "LINE")))) (setq sad (ssadd) s (car (entsel "\n Select polyline :")) ) (eq (cdr (assoc 0 (setq e (entget s)))) "LWPOLYLINE") ) (repeat (setq i (sslength ss)) (setq ent (entget (setq sn (ssname ss (setq i (1- i)))))) (if (and (vlax-invoke (vlax-ename->vla-object s) 'IntersectWith (vlax-ename->vla-object sn) acExtendNone) (or (equal (_Ang ent) (* pi 0.5) 1e-4) (equal (_Ang ent) (* pi 1.5) 1e-4)) ) (ssadd sn sad) ) ) ) (sssetfirst nil sad) (princ) ) Quote
pBe Posted March 20, 2013 Posted March 20, 2013 (defun c:WhereYouAt (/ e int pts mn mx dist tmpht i HtList p1 p2 p3p4) (setq os (getvar 'osmode )) (setvar 'osmode 0) (cond ((and (setq HtList nil e (car (entsel "\nSelect Polyline:")) ) (setq int (getdist "\nEnter Interval:")) (Setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (ent) (= (car ent) 10)) (entget e)))) (progn (vla-GetBoundingBox (vlax-ename->vla-object e) 'mn 'mx) (setq mn (vlax-safearray->list mn) mx (vlax-safearray->list mx) dist (- (car mx) (car mn)) tmpht (- (cadr mx) (cadr mn)) i int ) ) (while (< i dist) (setq p1 (polar mn 0 i) p2 (polar p1 (/ pi 2.0) tmpht) ) (setq p3p4 (vl-some '(lambda (x y) (if (<= (car x) (car p1) (car y)) (list x y) ) ) pts (cdr pts) ) ) (setq HtList (append HtList (list (inters p1 p2 (car p3p4) (cadr p3p4)))) i (+ i int) ) (setq pts (member (car p3p4) pts)) ) (foreach p HtList (command "_point" p)) ) ) )(setvar 'osmode os) (princ) ) Quote
Costinbos77 Posted March 21, 2013 Author Posted March 21, 2013 (edited) Thanks for your answers. Since this problem is part of a larger program, I have taken polyline coordinates and the coordinates of points 1,2,3 ... (so vertical lines does not exist). Initially, I opted for taking the polyline coordinate pairs 2 and checking all of intersection with the vertical lines. (setq length-polylinelist (length polylinelist ) i 0) (while (< i length-polylinelist ) (setq p1 (nth i polylinelist) i (1+ i) p2 (nth i polylinelist) ) (foreach p listpoints123... (if [color=red](setq pc (inters p1 p2 p (mapcar '+ '(0 100) p ))[/color] ... ) ) ) But in your examples (Tharwat) , I saw a simpler method: pc = (vlax-invoke (vlax-ename->vla-object poly) 'IntersectWith (vlax-ename->vla-object line) acExtendOtherEntity) (195.558 111.199 0.0) Which is a more direct method than the initial idea. But instead of object names, can be given lists coordinates ? Edited March 22, 2013 by Costinbos77 Quote
Lee Mac Posted March 21, 2013 Posted March 21, 2013 See this thread: www.theswamp.org/index.php?topic=43630 Quote
Costinbos77 Posted March 21, 2013 Author Posted March 21, 2013 (edited) Thanks Lee Mac . _polyinters Function runs faster than code below? ; polylinie = polyline object ; lisXYLin = list with coordinates of points 1, 2, 3, ... (foreach p lisXYLin (setq linie (vla-AddLine MSpace (vlax-3d-point p) (vlax-3d-point (mapcar '+ (list 0 100) p))) ) ; vertical line (if [color=red](setq pc (vlax-invoke polylinie 'IntersectWith linie acExtendBoth))[/color] ;_ end of setq (progn (setq dad (distance p pc)) ;_ end of set ; ....... (entmake (list '(0 . "TEXT") ... )) ; write a text )) ;_ end of if pc (if (and linie (not (vlax-erased-p linie)) ) (vla-Delete linie) ) ;_ end of if and ) ; f Edited March 22, 2013 by Costinbos77 Quote
Lee Mac Posted March 21, 2013 Posted March 21, 2013 _polyinters Function runs faster than code below? _polyinters is not creating any temporary objects and hence should perform much faster, however the function is limited for use with straight-segmented LWPolylines and could be optimised if testing multiple line vectors for intersection. Quote
fixo Posted March 21, 2013 Posted March 21, 2013 Sounds like you want to create profile see if this helps, bottom line is already drawn on your profile grid (defun c:profL(/ *error* adoc en en2 ent ent2 ept ni obj pts) (vl-load-com) (defun *error* (msg) (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)) ) (cond ((or (not msg) (member msg '("console break" "Function cancelled" "quit / exit abort")) ) ) ((princ (strcat "\nError: " msg))) ) (princ) ) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) ) (vla-startundomark adoc ) (if (and (setq ent (entsel "\nSelect top curve : ")) (setq ent2 (entsel "\nSelect bottom curve >>"))) (progn (setq en (car ent) pts (vl-remove-if 'not (mapcar '(lambda (x)(if (= 10 (car x))(trans (cdr x) 1 0)))(entget en))) en2 (car ent2) obj (vlax-ename->vla-object en2) ) (foreach pt pts (setq ept (vlax-curve-getclosestpointto obj pt)) (command "_line" "_non" pt "_non" ept "") ) ) ) (*error* nil) (princ) ) Quote
Costinbos77 Posted March 22, 2013 Author Posted March 22, 2013 (edited) Thank you very much for your help. I found the best function for what I am looking for . I have replaced : [color=black](setq pc (vlax-invoke polylinie 'IntersectWith linie acExtendBoth))[/color] with : (setq pc (vlax-curve-getClosestPointToProjection polylinie p '(0 1 0))) And there is no need to create temporary lines . Thanks fixo, your example was very helpful. I tried with function vlax-curve-getclosestpointto , but it was not what I needed. Yes , is a profile, but not all lines go to vertices ploliliniei section (#1). Edited March 22, 2013 by Costinbos77 Quote
pBe Posted March 25, 2013 Posted March 25, 2013 (setq pc (vlax-curve-getClosestPointToProjection polylinie p [b][i]'(0 1 0)[/i][/b])) Clever Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.