Author Topic: How to get all parameters at the self intersection of a curve?  (Read 9830 times)

0 Members and 1 Guest are viewing this topic.

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
If a curve intersect with itself,how to get the second parameter (or the third parameter ,or more....) ?
I mean: we can use (vlax-curve-getParamAtPoint  curve intersectPoint) to get the parameter that from start point to its first intersection,then go on,it will have a second  intersection at the same point,so question is ,vlax-curve-getParamAtPoint just returns a single value,we don't know other parameters at this point,how to get them?
I am a bilingualist,Chinese and Chinglish.

Spike Wilbury

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #1 on: April 22, 2009, 11:29:22 AM »
get the intersection of the same curve using:

vla-intersectwith

then, use those points to extract their params.

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: How to get all parameters at the self intersection of a curve?
« Reply #2 on: April 22, 2009, 09:11:13 PM »
get the intersection of the same curve using:

vla-intersectwith

then, use those points to extract their params.
I know how to use vla-intersectwith,but sometimes this kind of curve just has a point of intersection,I want to know every parameter at this point.
Luis,thanks.
I am a bilingualist,Chinese and Chinglish.

Spike Wilbury

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #3 on: April 22, 2009, 09:58:33 PM »
get the intersection of the same curve using:

vla-intersectwith

then, use those points to extract their params.
I know how to use vla-intersectwith,but sometimes this kind of curve just has a point of intersection,I want to know every parameter at this point.
Luis,thanks.

I see that I missunderstood your question, what's your idea?, do you want to recreate the curve? or split the curve? - that curve looks like a spline, I have done the convertion to polyline but it end up being by approximation, something by the way available now in A2010... is that what you are after? if it is you will need to use C++ and ARX for the task.

Or explain in more detail.... :)

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: How to get all parameters at the self intersection of a curve?
« Reply #4 on: April 22, 2009, 10:31:58 PM »
Sometimes we want to get these parameters to get all the length of segements that divided at this point,sometimes to split this curve at this point,and so on.
I think this question maybe  hasn't a direct answer.We need to split or break it and get these parameters.
for a lwpolyline,this question has a direct answer.
« Last Edit: April 22, 2009, 10:47:15 PM by highflybird »
I am a bilingualist,Chinese and Chinglish.

Spike Wilbury

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #5 on: April 22, 2009, 10:47:48 PM »
Sometimes we want to get these parameters to get all the length of segements that divided at this point,sometimes to split this curve at this point,and so on.
I think this question maybe  hasn't a direct answer.We need to split or break it and get these parameters.


I went to my library of functions.... and also did a quick test using a spline like the one you posted, now if you noticed, can you define and pick an intersection on that apparent intersection? (you can't no?)

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: How to get all parameters at the self intersection of a curve?
« Reply #6 on: April 22, 2009, 11:18:59 PM »
Yes,I can't. and sometimes I use vla-intersectwith, it doesn't work?
for example,in this file, I can't get the intersection.
Actually, I can't get a intersection with a command if it's a spline.
« Last Edit: April 22, 2009, 11:25:01 PM by highflybird »
I am a bilingualist,Chinese and Chinglish.

Spike Wilbury

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #7 on: April 22, 2009, 11:32:15 PM »
Yes,I can't. and sometimes I use vla-intersectwith, it doesn't work?
for example,in this file, I can't get the intersection.
Actually, I can't get a intersection with a command if it's a spline.

Yes....

The only thing I can think of is to use bpoly and create an internal boundary (that will be a region and if it is exploded converted to a spline), but the two outside spline parts are left out.

Or...

To convert the spline to polyline and work from there.

jxphklibin

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #8 on: April 23, 2009, 03:39:55 AM »
I wrote a routine, but only for LWPOLYLINE POLYLINE, does not apply for the SPLINE.

Aother problem, that is, if is a vertex and a self-intersection, then this point does not know how to do.
« Last Edit: April 23, 2009, 04:08:49 AM by Leeben »

cjw

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #9 on: April 23, 2009, 09:15:46 AM »
So, "To convert the spline to polyline ".

chlh_jd

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #10 on: August 16, 2012, 07:13:28 PM »
by this method can get the second param, but don't sure the intersections is correct .
Code: [Select]
(defun c:test  (/ en ips)
  (setq en (ssname (ssget ":E:S" '((0 . "SPLINE"))) 0))
  (setq ips (get-spline-cross-param en 1e-8))
  (if ips
    (foreach ip ips
      (entmake (list (cons 0 "POINT")
     (cons 10 (car ip))
     (cons 8 "Temp")
     (cons 62 1)))
      (entmake (list (cons 0 "LINE")
     (cons 10 '(0 0 0))
     (cons 11 (vlax-curve-getpointatparam en (cadr ip)))
     (cons 8 "Temp")
     (cons 62 1)
     ))
      (entmake (list (cons 0 "LINE")
     (cons 10 '(0 0 0))
     (cons 11 (vlax-curve-getpointatparam en (caddr ip)))
     (cons 8 "Temp")
     (cons 62 2)
     ))
      (princ (strcat "\nFirst param = "
     (rtos (cadr ip) 2 6)
     " ; Second param = "
     (rtos (caddr ip) 2 6)
     " ;;")))
    )
  (princ)
  )
;;;
(defun get-spline-cross-param  (en eps / _oce l ips len en1 mid)
  ;;by GSLS(SS) 2012-8-17
  (setq _oce (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (if en
    (progn
      (setq l
     ((lambda (/ r )
(if
  (not
    (vl-catch-all-error-p
      (vl-catch-all-apply
(function vl-cmdf)
(list "_PEDIT"
      (vlax-vla-object->ename
(vla-copy (vlax-ename->vla-object en))
)
      ""
      99
      ""
      ))))
   (progn
     (setq
       l (ss-assoc 10 (entget (setq r (entlast)))))
     (if (vlax-curve-isClosed r)
       (setq l (append l (list (car l))))
       )
     (entdel r)
     )
   )
l
)))
      (setq ips
     ((lambda (l isclosed / firstp p p0 p1 p2 p3 l1 ips)
(setq firstp t)
(while l
  (cond ((not firstp)
(setq p0 p1
       p1 (car l)
       l  (cdr l))
)
((and firstp isclosed)
(setq p0     (last l)
       p1     (car l)
       l      (cdr l)
       firstp nil)
)
(firstp
(setq p0     (car l)
       p1     (cadr l)
       l      (cddr l)
       firstp nil)
)
)
  (setq l1 l)
  (while (cadr l1)
    (setq p2 (car l1)
  p3 (cadr l1)
  l1 (cdr l1))
    (if (setq p (inters p0 p1 p2 p3))
      (setq ips (cons p ips))))
  )
ips
)
       l
       (vlax-curve-isclosed en)))
      (if ips
(progn
  (setq len (vlax-curve-getdistatparam
      en
      (vlax-curve-getendparam en)))
  (if
    (not (vl-catch-all-error-p
   (vl-catch-all-apply
     (function vl-cmdf)
     (list
       "_REVERSE"
       (vlax-vla-object->ename
(vla-copy (vlax-ename->vla-object en))
)
       ))))
     (progn        
       (setq en1 (entlast))
       (setq ipl
      (if
   (not
     (minusp
       (vlax-safearray-get-u-bound
(vlax-variant-value
   (setq mid
  (vla-IntersectWith
    (vlax-ename->vla-object
      en)
    (vlax-ename->vla-object
      en1)
    0
    )
)
   )
1
)
       )
     )
    (list-comp (vlax-safearray->list
(vlax-variant-value mid))
       3
       )
    ))
       (setq ips (mapcar (function (lambda (x)
    (car (vl-sort ipl (function (lambda (p1 p2)
      (< (distance x p1) (distance x p2))))))
     )
   )
ips))
       (setq
ips (mapcar
       (function
(lambda (p / is ps paf pas)
    (setq paf (vlax-curve-getparamatpoint
en
p)
   pas (vlax-curve-getparamatpoint
en1
p)
   pas (vlax-curve-getparamatdist
en
(-
   len
   (vlax-curve-getdistatparam
     en1
     pas)))  
   )
   (setq is T)
   (while is
     (setq ps (vlax-curve-getpointatparam en pas))
     (if (equal p ps eps)
       (setq is nil)
       (setq pas (+ pas (* (- (vlax-curve-getparamatpoint en (vlax-curve-getclosestpointto en (midpt p ps))) pas) 2.)))
       )
     )      
   (list p paf pas)
   ) ;_lambda
) ;_function
       ips) ;_mapcar
) ;_setq
       (entdel en1)        
       ) ;_progn      
     ) ;_if en1
  ) ;_progn
) ;_if ips
      ) ;_progn
    ) ;_if en
  (setvar "CMDECHO" _oce)
  ips
  )
;;
(defun ss-assoc (a lst / b res)
  (while (setq b (assoc a lst))
    (setq lst  (cdr (member b lst))
  res (cons (cdr b) res)
    ))(reverse res))
(defun list-comp (a b / mid rslt)
    (repeat (/ (length a) b)
      (setq mid nil)
      (repeat b
(setq mid (cons (car a) mid)
      a   (cdr a)
)
      )
      (setq rslt (cons (reverse mid) rslt))
    )
  (if a (reverse (cons a rslt))
    (reverse rslt))
  )
« Last Edit: August 16, 2012, 07:24:51 PM by chlh_jd »

Faster

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #11 on: August 17, 2012, 04:04:10 AM »
Only for LWpolyline:
Code - Auto/Visual Lisp: [Select]
  1. (defun getlwparamatpoint (LW PT / DATA DPA PA PARS EL V K NEWEL A)
  2.   (setq data (entget lw) dpa 0)
  3.     (setq pars (cons (setq dpa (+ dpa pa)) pars)
  4.           dpa (+ 1 (fix dpa))
  5.           el (entget lw)
  6.           v (- (cdr (assoc 90 el)) (fix pa) 1)
  7.           k -1
  8.           newel nil
  9.           )
  10.     (while el
  11.       (setq a (car el)
  12.             el (cdr el)
  13.             )
  14.       (cond
  15.         ((= 10 (car a))
  16.          (if (< k (fix pa))
  17.            (setq k (1+ k)
  18.                  el (cdddr el)
  19.                  )
  20.            (setq newel (cons a newel))
  21.            )
  22.          )
  23.         ((= 90 (car el))
  24.          (setq newel (cons (cons 90 v) newel))
  25.          )
  26.         (t (setq newel (cons a newel)))
  27.        
  28.         )
  29.       )
  30.     (entmod (reverse newel))
  31.     (entupd lw)
  32.     )
  33.   (entmod data)
  34.   (reverse pars)
  35.   )
  36. (defun c:test (/ e p pars)
  37.   (setq e (car (entsel "\nSelect a lwpolyline:"))
  38.         p (getpoint "\nSelect Point : ")
  39.         )
  40.   (if (and e p)
  41.     (progn
  42.     (setq pars (getlwparamatpoint e p))
  43.     (if pars
  44.       (progn
  45.         (princ "\n Params is : ")
  46.         (foreach a pars (princ a) (princ "  "))
  47.         )
  48.       (princ "\nNull...")
  49.       )
  50.     )
  51.     )
  52.   (princ)
  53.   )

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to get all parameters at the self intersection of a curve?
« Reply #12 on: August 17, 2012, 06:55:24 AM »
Nice idea Faster  8-)

Faster

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #13 on: August 17, 2012, 11:05:03 AM »
This is my solutions:
Code: [Select]
;;Get all parameters for lwpolyline.
(defun gxl-getlwparamatpoint (LW PT / DATA DPA PA PARS EL V K NEWEL A)
  (setq data (entget lw) dpa 0)
  (while (setq pa (vlax-curve-getParamAtPoint lw pt))
    (setq pars (cons (setq dpa (+ dpa pa)) pars)
  dpa (+ 1 (fix dpa))
  el (entget lw)
  v (- (cdr (assoc 90 el)) (fix pa) 1)
  k -1
  newel nil
  )
    (while el
      (setq a (car el)
    el (cdr el)
    )
      (cond
((= 10 (car a))
(if (< k (fix pa))
   (setq k (1+ k)
el (cdddr el)
)
   (setq newel (cons a newel))
   )
)
((= 90 (car el))
(setq newel (cons (cons 90 v) newel))
)
(t (setq newel (cons a newel)))

)
      )
    (entmod (reverse newel))
    (entupd lw)
    )
  (entmod data)
  (reverse pars)
  )
;;Get all parameters for spline.
(defun gxl-getsplparamatpoint (SPL PT     /      GETPARAM OBJSPL
   OBJCIRCLE      PL       PARS0
   PA     PARS     RESULT
  )
  (defun getparam (CURVE PA1 PA2 P / PA P0 P1 P2)
    (setq pa (* 0.5 (+ pa1 pa2))
  p0 (vlax-curve-getPointAtParam curve pa)
    )
    (cond
      ((equal (setq p1 (vlax-curve-getPointAtParam curve pa1))
      (setq p2 (vlax-curve-getPointAtParam curve pa2))
      1e-8
       )
       pa
      )
      ((< (distance p p1) (distance p p2))
       (getparam curve pa1 pa p)
      )
      ((< (distance p p2) (distance p p1))
       (getparam curve pa pa2 p)
      )
      (t nil)
    )
  )
  (if (vlax-curve-getParamAtPoint spl pt)
    (progn
      (setq objspl    (vlax-ename->vla-object spl)
    objcircle (vla-addcircle
(vlax-get-property
  (vla-get-ActiveDocument (vlax-get-acad-object))
  (if (= 1 (getvar 'CVPORT))
    'PaperSpace
    'ModelSpace
  )
)
(vlax-3d-point pt)
1e-3
      )
      )
      (setq
pl (vlax-invoke objspl 'IntersectWith objcircle acExtendNone)
      )
      (vla-delete objcircle)
      (while pl
(setq pars0 (cons (vlax-curve-getParamAtPoint
   spl
   (list (car pl) (cadr pl) (caddr pl))
)
pars0
   )
      pl   (cdddr pl)
)
      )
      (setq pars0 (vl-sort pars0 '<))
      (while pars0
(setq pa (car pars0)
      pars0 (cdr pars0)
      )
(if pars0
  (progn
    (if (< (distance (vlax-curve-getPointAtParam spl pa) (vlax-curve-getPointAtParam spl (car pars0))) 2.0001e-3)
      (setq pars (cons (list pa (car pars0)) pars)
    pars0 (cdr pars0)
    )
      (setq pars (cons (list (if (vlax-curve-getpointatParam spl (- pa 1e-3))  (- pa 1e-3) (vlax-curve-getstartParam spl))
   (if (vlax-curve-getpointatParam spl (+ pa 1e-3))  (+ pa 1e-3) (vlax-curve-getendParam spl))
   )
     pars
     )
  )
      )
    )
  (setq pars (cons (list (if (vlax-curve-getpointatParam spl (- pa 1e-3))  (- pa 1e-3) (vlax-curve-getstartParam spl))
   (if (vlax-curve-getpointatParam spl (+ pa 1e-3))  (+ pa 1e-3) (vlax-curve-getendParam spl))
   )
     pars
     )
  )
  )
)
      (foreach par (reverse pars)
(if (setq pa (getparam spl (car par) (cadr par) pt))
  (setq result (cons pa result))
)
      )
      (reverse result)

    ) ;_ progn
  )
)
;;Get all parameters for any curves.
(defun gxl-getparamatpoint (CURVE PT / CURVETYPE ENL DATA E EL PAR)
  (if (= 'VLA-OBJECT (type curve))
    (setq curve (vlax-vla-object->ename curve))
  )
  (cond
    ((= "SPLINE" (setq curvetype (cdr (assoc 0 (entget curve)))))
     (gxl-getsplparamatpoint curve pt)
    )
    ((= "LWPOLYLINE" curvetype)
     (GXL-GETLWPARAMATPOINT curve pt)
    )
    ((= "POLYLINE" curvetype)
     (setq enl (entget curve)
   data
(list
  '(0 . "LWPOLYLINE")
  '(100 . "AcDbEntity")
  (assoc 8 enl)
  '(100 . "AcDbPolyline")
  (cons 90 (fix (vlax-curve-getendparam curve)))
  (cons 70
(if (vlax-curve-isClosed curve)
  1
  0
)
  )
)
   e curve
     )
     (while (and
      (setq e (entnext e))
      (/= (cdr (assoc 0 (entget e))) "SEQEND")
    )
       (setq el (entget e))
       (setq
data (append data
      (list (reverse (cdr (reverse (assoc 10 el))))
    (assoc 40 el)
    (assoc 41 el)
    (assoc 42 el)
      )
      )
       )

     )
     (entmake data)
     (setq curve (entlast))
     (setq par (GXL-GETLWPARAMATPOINT curve pt))
     (entdel curve)
     par
    )
    (t
     (if (setq par (vlax-curve-getParamAtPoint curve pt))
       (list par)
     )
    )
  )
)
(defun c:test (/ e p pars)
  (setq e (car (entsel "\nSelect a curve:"))
p (getpoint "\nSelect Point : ")
)
  (if (and e p)
    (progn
    (setq pars (gxl-getparamatpoint e p))
    (if pars
      (progn
(princ "\n Params is : ")
(foreach a pars (princ a) (princ "  "))
)
      (princ "\nNull...")
      )
    )
    )
  (princ)
  )

chlh_jd

  • Guest
Re: How to get all parameters at the self intersection of a curve?
« Reply #14 on: August 18, 2012, 04:24:42 AM »
This is my solutions:
Code: [Select]
;;Get all parameters for lwpolyline.
(defun gxl-getlwparamatpoint (LW PT / DATA DPA PA PARS EL V K NEWEL A)
  (setq data (entget lw) dpa 0)
  (while (setq pa (vlax-curve-getParamAtPoint lw pt))
......   
 
Good solution !