Author Topic: 2 points - crossing fence intersections - fast solution  (Read 3549 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
2 points - crossing fence intersections - fast solution
« on: June 20, 2015, 11:54:48 AM »
Hi, I have an issue to solve... I have 2 points and I want to check if some entities passes through fence created by those 2 points... I don't want to use (ssget "_F" (list p1 p2)) as it's slow and for some reason it's little buggy... I need checking weather points or entities are on visible screen or not... I just need fast and correct return (I don't want to entmake line p1 p2 and set visibility DXF 66 to 1 and check it with 'IntersectWith method - I don't want to iterate through database)... So if someone knows how please reply... Any help will be nice...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: 2 points - crossing fence intersections - fast solution
« Reply #1 on: June 20, 2015, 05:35:57 PM »
I solved problem still with iteration, but fortunately now my main routine works correct (slow but correct)...

Code - Auto/Visual Lisp: [Select]
  1. (defun p1p2intss ( p1 p2 ss df / i ent k p pl v1 d pll rtn ) (vl-load-com)
  2.   (repeat (setq i (sslength ss))
  3.     (setq ent (ssname ss (setq i (1- i))))
  4.       (progn
  5.         (setq k -0.5)
  6.           (setq p (vlax-curve-getpointatdist ent (* df (setq k (1+ k)))))
  7.           (setq pl (cons p pl))
  8.         )
  9.       )
  10.     )
  11.   )
  12.   (setq v1 (mapcar '/ (mapcar '- p2 p1) (list (setq d (distance p1 p2)) d d)))
  13.   (setq k -0.5)
  14.   (repeat (fix (/ d df))
  15.     (setq p (mapcar '+ p1 (mapcar '* v1 (list (* df (setq k (1+ k))) (* df k) (* df k)))))
  16.     (setq pll (cons p pll))
  17.   )
  18.   (while (and (not rtn) pll)
  19.     (setq p (car pll))
  20.     (if (vl-some '(lambda ( x ) (< (distance x p) df)) pl)
  21.       (setq rtn t)
  22.       (setq rtn nil)
  23.     )
  24.     (setq pll (cdr pll))
  25.   )
  26.   rtn
  27. )
  28.  

Thanks, M.R.
« Last Edit: June 21, 2015, 03:20:57 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: 2 points - crossing fence intersections - fast solution
« Reply #2 on: June 21, 2015, 06:44:01 AM »
Marko, I don't understand. Your solution does not match the criteria set out in your first post. Also there is a new criterion ('only curves'). And where in your code do you check 'whether points or entities are on visible screen or not'?

As an aside: Your code assumes that one of the point lists (pll) is the shortest of the two. This need not be the case.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: 2 points - crossing fence intersections - fast solution
« Reply #3 on: June 21, 2015, 10:25:47 AM »
Roy, yes I need it just for curves and placed in WCS... Two points are also in WCS... As I said I don't want to use (ssget) and not to create dummy line from p1 to p2... My function provides me the result quite fine to what I've expected (intersection may occur as a result only inaccurate at some small fuzz distances near endpoints of curves, otherwise I need to get T or nil and function does this pretty good)... Yes pll point list is smaller point list and it describes points representing imaginary line from p1 to p2... So I am checking smaller distances near those points that represent p1 p2 line and I think function may be very good and for checking 3D "intersections"... I have bigger code where I use this function in lieu to (ssget) and it doesn't matter weather curves or supplied points p1 or p2 are visible on screen or not... Function should calculate correct result...

Hope I've explained, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: 2 points - crossing fence intersections - fast solution
« Reply #4 on: June 22, 2015, 03:14:37 AM »
Marko, you have misunderstood my previous post. I do understand your code. But how can it be 'quite fine' if it does not meet your own criteria? Your solution uses ssget (how else do you get a selection set?), it is iterative and slow. Three things that you clearly did not want.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: 2 points - crossing fence intersections - fast solution
« Reply #5 on: June 22, 2015, 04:11:06 AM »
Why not simply:
Code - Auto/Visual Lisp: [Select]
  1. (defun fence-p ( p q )
  2.     (eval
  3.         (list 'defun 'fence-p '( p q / r )
  4.                '(vlax-3D-point (mapcar 'min p q))
  5.                '(vlax-3D-point (mapcar 'max p q))
  6.             )
  7.            '(setq r (ssget "_F" (list p q)))
  8.            'r
  9.         )
  10.     )
  11.     (fence-p p q)
  12. )

RGUS

  • Newt
  • Posts: 106
Re: 2 points - crossing fence intersections - fast solution
« Reply #6 on: June 22, 2015, 04:35:08 AM »
Why not simply:
Code - Auto/Visual Lisp: [Select]
  1. (defun fence-p ( p q )
  2.     (eval
  3.         (list 'defun 'fence-p '( p q / r )
  4.                '(vlax-3D-point (mapcar 'min p q))
  5.                '(vlax-3D-point (mapcar 'max p q))
  6.             )
  7.            '(setq r (ssget "_F" (list p q)))
  8.            'r
  9.         )
  10.     )
  11.     (fence-p p q)
  12. )

Lee... I have to say... I really, really love the way you say... "Why not simply" ... and the rest of us go.... sigh!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: 2 points - crossing fence intersections - fast solution
« Reply #7 on: June 22, 2015, 06:19:03 AM »
I don't know if Marko is referring to this problem when he speaks of 'buggy' in his first post, but (ssget "_F" ...) has a known issue with non-continuous linetypes. If the fence passes through a 'linetype gap' of an entity it will not be selected at that intersection. A similar problem occurs with the "_C" option of ssget: if the crossing falls inside a linetype gap of, for example, a line, the line will not be selected.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: 2 points - crossing fence intersections - fast solution
« Reply #8 on: June 22, 2015, 06:42:33 AM »
Lee... I have to say... I really, really love the way you say... "Why not simply" ... and the rest of us go.... sigh!

 :lol:

(ssget "_F" ...) has a known issue with non-continuous linetypes. If the fence passes through a 'linetype gap' of an entity it will not be selected at that intersection. A similar problem occurs with the "_C" option of ssget: if the crossing falls inside a linetype gap of, for example, a line, the line will not be selected.

The following may reduce (but not completely eliminate) that risk:
Code - Auto/Visual Lisp: [Select]
  1. (defun fence-p ( p q )
  2.     (eval
  3.         (list 'defun 'fence-p '( p q / idx obj rtn sel tmp )
  4.                '(vlax-3D-point (mapcar 'min p q))
  5.                '(vlax-3D-point (mapcar 'max p q))
  6.             )
  7.            '(cond
  8.                 (   (setq rtn (ssget "_F" (list p q))))
  9.                 (   (setq sel (ssget "_C" p q))
  10.                     (setq tmp (entmakex (list '(0 . "LINE") (cons 10 p) (cons 11 q)))
  11.                           tmp (vlax-ename->vla-object tmp)
  12.                           idx -1
  13.                     )
  14.                     (while (and (setq obj (ssname sel (setq idx (1+ idx)))) (null rtn))
  15.                         (if (vlax-method-applicable-p (setq obj (vlax-ename->vla-object obj)) 'intersectwith)
  16.                             (setq rtn (vlax-invoke obj 'intersectwith tmp acextendnone))
  17.                         )
  18.                     )
  19.                     (vla-delete tmp)
  20.                 )
  21.             )  
  22.            '(and rtn)
  23.         )
  24.     )
  25.     (fence-p p q)
  26. )

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: 2 points - crossing fence intersections - fast solution
« Reply #9 on: June 22, 2015, 07:26:39 AM »
Marko, you have misunderstood my previous post. I do understand your code. But how can it be 'quite fine' if it does not meet your own criteria? Your solution uses ssget (how else do you get a selection set?), it is iterative and slow. Three things that you clearly did not want.

Yes, firstly in my main routine I select entities, but then I don't want to repeat (ssget "_F" (list p1 p2))... Yes, it's also buggy because of linetypes what I've forgot to test, but anyhow if there is some better solution than this "ssget", I am all your ears...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: 2 points - crossing fence intersections - fast solution
« Reply #10 on: June 22, 2015, 08:26:09 AM »
Hi again, I want to thank to all... I've found that (ssget "_F" (list p1 p2)) was not buggy, but I forgot to (entdel ent) before (ssget) call and as I was testing (not (ssget "_F" (list p1 p2))) it always returned nil and my then statement wasn't processed... Now that's fixed, but have never thought ab linetypes like Roy stated... Nevertheless my issue was solved as I don't use too much dashed lines (curves) and now main routine is fast and produce desired results... Thanks to all, I just stumbled on a problem I tried to solve on my own way and missed to deeply check my main routine... Sorry for my subjective observation ab (ssget), but who knows maybe someone will find this topic useful after all...

Once again my apology if I took someones valuable time in tying to help me, I won't forget... Marko R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube