Grrr Posted July 10, 2016 Posted July 10, 2016 Hi guys, I was just exploring the vlax-curve-*** functions, and a question came up: Is it possible to find the intersection between two curves? Quote
BIGAL Posted July 11, 2016 Posted July 11, 2016 Why not VLAX-INTERSECTWITH (setq intpt2 (vlax-invoke obj3 'intersectWith obj1 acExtendThisEntity)) Quote
Grrr Posted July 11, 2016 Author Posted July 11, 2016 Thanks, BIGAL ! Looks like it was easier than I thought. Quote
BIGAL Posted July 12, 2016 Posted July 12, 2016 No worries there are 4 conditions you can use extend is 1 can use 1 2 3 4 rather than long acex.... Quote
Grrr Posted July 12, 2016 Author Posted July 12, 2016 I made a small progress with the code: [b][color=BLACK]([/color][/b]defun c:test [b][color=FUCHSIA]([/color][/b] / ent1 ent2 obj1 obj2 int-lst cnt pt pt-lst [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]vl-load-com[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setvar 'errno 0[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]setq ent1 [b][color=BLUE]([/color][/b]car [b][color=RED]([/color][/b]entsel [color=#2f4f4f]"\nPick first curve: "[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq obj1 [b][color=BLUE]([/color][/b]vlax-ename->vla-object ent1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]or [b][color=GREEN]([/color][/b]= [b][color=BLUE]([/color][/b]getvar 'errno[b][color=BLUE])[/color][/b] 7[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]null ent1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]princ [color=#2f4f4f]"\nYou missed, try again!"[/color][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]setq ent2 [b][color=BLUE]([/color][/b]car [b][color=RED]([/color][/b]entsel [color=#2f4f4f]"\nPick second curve: "[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq obj2 [b][color=BLUE]([/color][/b]vlax-ename->vla-object ent2[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]eq ent1 ent2[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]or [b][color=GREEN]([/color][/b]= [b][color=BLUE]([/color][/b]getvar 'errno[b][color=BLUE])[/color][/b] 7[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]null ent2[b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]princ [color=#2f4f4f]"\nYou missed, try again!"[/color][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq int-lst [b][color=NAVY]([/color][/b]vlax-safearray->list [b][color=MAROON]([/color][/b]vlax-variant-value [b][color=GREEN]([/color][/b]vla-IntersectWith obj1 obj2 acExtendNone[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq cnt [b][color=NAVY]([/color][/b]- 1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]foreach x int-lst [b][color=NAVY]([/color][/b]if [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]setq pt [b][color=BLUE]([/color][/b]list [b][color=RED]([/color][/b]nth [b][color=PURPLE]([/color][/b]setq cnt [b][color=TEAL]([/color][/b]+ cnt 1[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] int-lst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]nth [b][color=PURPLE]([/color][/b]setq cnt [b][color=TEAL]([/color][/b]+ cnt 1[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] int-lst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]nth [b][color=PURPLE]([/color][/b]setq cnt [b][color=TEAL]([/color][/b]+ cnt 1[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] int-lst[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]car pt[b][color=GREEN])[/color][/b] [color=#8b4513]; X check[/color] [b][color=GREEN]([/color][/b]cadr pt[b][color=GREEN])[/color][/b] [color=#8b4513]; Y check[/color] [b][color=GREEN]([/color][/b]caddr pt[b][color=GREEN])[/color][/b] [color=#8b4513]; Z check[/color] [b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq pt-lst [b][color=GREEN]([/color][/b]cons pt pt-lst[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq pt-lst [b][color=NAVY]([/color][/b]reverse pt-lst[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]progn [b][color=NAVY]([/color][/b]setvar 'PDMODE 35[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]foreach x pt-lst [b][color=MAROON]([/color][/b]if x [b][color=GREEN]([/color][/b]progn [b][color=BLUE]([/color][/b]entmakex [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]cons 0 [color=#2f4f4f]"POINT"[/color][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cons 10 x[b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]cons 62 1[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]princ [color=#2f4f4f]"\n"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]print x[b][color=BLUE])[/color][/b] [b][color=GREEN])[/color][/b] [b][color=MAROON])[/color][/b] [b][color=NAVY])[/color][/b] [b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]princ[b][color=FUCHSIA])[/color][/b] [b][color=BLACK])[/color][/b][color=#8b4513];defun [/color] I'm not sure if my method is sloppy or not. The next step I'll think about is to work with an selection set: -SSGET with (cons 0 "CIRCLE,ARC,*LINE*) -Iterate trough the selection set and use permutation for every entity, until all of the intersections are found Quote
Grrr Posted July 12, 2016 Author Posted July 12, 2016 So heres the next version (that was in my head): ; Prompts for a SS (either implied or user) until theres one: (defun C:test ( / SS SSloop lst assoc-lst cnt ) (setq SSloop T) (while SSloop (if (not (setq SS (ssget "_I"))) (setq SS (ssget "_:L")) (sssetfirst nil nil) ) (if (and SS (>= (sslength SS) 1)) (progn (setq lst (ss->lst SS)) (setq assoc-lst (combine-itms lst)) (print assoc-lst) (setq cnt 0) (repeat (length assoc-lst) (ins-pt (car (nth cnt assoc-lst)) (cdr (nth cnt assoc-lst)) ) (setq cnt (+ cnt 1)) ) (setq SSloop nil) ) ) ) (princ) ) (defun ss->lst (ss / i l) (if (eq (type ss) 'pickset) (repeat (setq i (sslength ss)) (setq l (cons (ssname ss (setq i (1- i))) l)) ) ) ) ; So this is the source list: A B C D ; The result should be like this: (("A" . "B") ("A" . "C") ("A" . "D") ("B" . "C") ("B" . "D") ("C" . "D")) ; So there would be combination between every 2 items (defun combine-itms ( lst / oldlst newlst cnt itm ) ; (setq lst (list "A" "B" "C" "D")) (setq oldlst lst) (setq newlst (list)) ; the result should be: AB AC AD BC BD CD (setq cnt 0) ; set a counter (while (> (length lst) 0) ; repeat until all the items are removed from the list (foreach x oldlst ; iterate trough the list (if (and (not (eq (nth cnt lst) x)) ; check if the current item doesnt duplicate itself (example result would be: AA BB CC DD) (not (member (cons (nth cnt lst) x) newlst )) (not (member (cons x (nth cnt lst)) newlst )) lst ; check if the lst is not nil ) (progn (setq itm (cons (nth cnt lst) ; the current item x ; iteration item ) ) ; combined item (setq newlst (cons itm newlst)) ; add the combined item in a new list ) ) ); foreach (setq lst (remove_nth lst cnt)) ; returns the same list without the item on "cnt" position (redefine the list) ;(setq cnt (+ cnt 1)) ; increment the counter ); repeat (setq newlst (reverse newlst)) ; (print newlst) ; (princ) ) ; LM - remove nth (returns the same list with the removed item): (defun remove_nth ( lst n / lstn ) (setq n (1+ n)) (foreach x lst (if (/= 0 (setq n (1- n))) (setq lstn (cons x lstn)))) (reverse lstn) ) (defun ins-pt ( ent1 ent2 / obj1 obj2 int-lst cnt pt pt-lst ) ; (setq ent1 (car (entsel "\nPick first curve: "))) (setq obj1 (vlax-ename->vla-object ent1)) ; (setq ent2 (car (entsel "\nPick second curve: "))) (setq obj2 (vlax-ename->vla-object ent2)) (setq int-lst (vlax-safearray->list (vlax-variant-value (vla-IntersectWith obj1 obj2 acExtendNone)))) (setq cnt (- 1)) (foreach x int-lst (if (and (setq pt (list (nth (setq cnt (+ cnt 1)) int-lst) (nth (setq cnt (+ cnt 1)) int-lst) (nth (setq cnt (+ cnt 1)) int-lst))) (car pt) ; X check (cadr pt) ; Y check (caddr pt) ; Z check ) (setq pt-lst (cons pt pt-lst)) ) ) (setq pt-lst (reverse pt-lst)) (progn (setvar 'PDMODE 35) (foreach x pt-lst (if x (progn (entmakex (list (cons 0 "POINT") (cons 10 x) (cons 62 1))) ; (princ "\n")(print x) ) ) ) ) (princ) );defun I had to write this "combine-itms" subfunction bymyself.. and overall the code is very messy, probably it could be shortened (also modified my previous code to a subfunction named "ins-pt"). The only similar code to this that I know, is the "Break.lsp" by CAB - but I didn't took the time to analyse it (just went with the straight attempt for my idea). Quote
Lee Mac Posted July 12, 2016 Posted July 12, 2016 So heres the next version (that was in my head): (setq int-lst (vlax-safearray->list (vlax-variant-value (vla-IntersectWith obj1 obj2 acExtendNone)))) Try using the above expression with two objects which do not intersect - Note that the upper bound of an empty safearray is negative. Here are two solutions: https://www.theswamp.org/index.php?topic=43461.msg486965#msg486965 You may also find these old functions useful: http://lee-mac.com/intersectionfunctions.html Quote
Grrr Posted July 13, 2016 Author Posted July 13, 2016 Try using the above expression with two objects which do not intersect - Note that the upper bound of an empty safearray is negative. Here are two solutions: https://www.theswamp.org/index.php?topic=43461.msg486965#msg486965 You may also find these old functions useful: http://lee-mac.com/intersectionfunctions.html Thanks Lee, I'm still lacking with that "safearray" knowledge ( just can't imagine what exactly it represents ). I was aware of your Intersection functions, but I tried to "re-write" this one as a practice.. now rechecking your code which is 4-5 times shorter Anyway I was trying to create similar function like your " LM:intersectionsinset ", which would return one assoc list like this: ( (list of point intersections) (list of angles of the tangency lines - 1st inters curve) (list of angles of the tangency lines - 2nd inters curve) ) Which would allow to insert/create objects at those points, and toggle the rotation (alignment on 1st or on the 2nd curve). Quote
motee-z Posted July 13, 2016 Posted July 13, 2016 any help to improve intersection curves as in attached drawing test.dwg Quote
motee-z Posted July 14, 2016 Posted July 14, 2016 until now no reply as if impossible to get intersection points in my case Quote
broncos15 Posted July 14, 2016 Posted July 14, 2016 until now no reply as if impossible to get intersection points in my caseLook at this thread, it seems to have solved your questions. https://www.theswamp.org/index.php?topic=48530.0 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.