Author Topic: get the distance between two points on pline  (Read 3256 times)

0 Members and 1 Guest are viewing this topic.

subbup

  • Guest
get the distance between two points on pline
« on: October 14, 2004, 04:22:18 AM »
Hello All,

I need to find distance between two points on pline.
I will supply entity and two points on pline.
It should return the distance.Any Ideas.
 :idea: I know that if we supply distance it will give the point on pline.

SMadsen

  • Guest
Re: get the distance between two points on pline
« Reply #1 on: October 14, 2004, 05:22:01 AM »
Quote from: subbup
I will supply entity and two points on pline.

If you supply two points on the pline, it'll be as easy as using the DISTANCE function.
Somehow I think there's more to your question, though? If so, can you explain further what the problem is?

subbup

  • Guest
get the distance between two points on pline
« Reply #2 on: October 14, 2004, 06:15:05 AM »
I could'e have given the clear description.

If the pline have number of vertexs we can't use that Distance function.

SMadsen

  • Guest
get the distance between two points on pline
« Reply #3 on: October 14, 2004, 06:29:52 AM »
Are you supplying the vertex number of the two points? Like: I want the distance between vertex no. 2 and vertex no. 4?

If so, is it the distance along the pline or the direct distance?

I promise that if I don't get it a third time then I won't bother you again :D

subbup

  • Guest
get the distance between two points on pline
« Reply #4 on: October 14, 2004, 06:43:17 AM »
The supplied points always may not be the vertexs. Those points may fall inbetween vertexs on pline.

I want to get the distance along the pline inbetween these two points.

SMadsen

  • Guest
get the distance between two points on pline
« Reply #5 on: October 14, 2004, 07:06:19 AM »
Oh ok. I think I get it. The pointsOnPline below will accept two points located on the polyline (or any curve object, actually) and return the distance along the object. If the points are not exactly on the object it will return nil (this can be adjusted so that points are projected onto the object if you wish).

The command function is just for testing it.

Code: [Select]
(defun pointsOnPline (obj p1 p2 / pd1 pd2)
  (vl-load-com)
  (if (= (type obj) 'ENAME)
    (setq obj (vlax-ename->vla-object obj))
  )
  (cond ((and (setq pd1 (vlax-curve-getDistAtPoint obj p1))
              (setq pd2 (vlax-curve-getDistAtPoint obj p2))
         )
         (- pd2 pd1)
        )
  )
)

(defun C:POP (/ ent p1 p2 dist)
  (setq ent (car (entsel "\nPick a polyline: ")))
  (setq p1 (getpoint "\nFirst point on pline: ")
        p2 (getpoint "\nSecond point on pline: ")
  )
  (and p1
       p2
       (if (setq dist (pointsOnPline ent p1 p2))
         (princ (strcat "\nDistance along pline: " (rtos dist)))
         (princ "\nOne or both points was not on pline")
       )
  )
  (princ)
)

subbup

  • Guest
get the distance between two points on pline
« Reply #6 on: October 14, 2004, 07:23:10 AM »
Thank you :D
It's working fine.

SMadsen

  • Guest
get the distance between two points on pline
« Reply #7 on: October 14, 2004, 07:28:02 AM »
Excellent!

whdjr

  • Guest
get the distance between two points on pline
« Reply #8 on: October 14, 2004, 08:22:12 AM »
[In my best Japanese accent]
Thank you master stig for that enlightening
code on relaxed curves.
[/In my best Japanese accent]
 :D  :D

SMadsen

  • Guest
get the distance between two points on pline
« Reply #9 on: October 14, 2004, 08:33:00 AM »
オーケーです (no problem)