Author Topic: Help. vlax-curve-getDistAtPoint Error (Real World Coordinate)  (Read 6088 times)

0 Members and 1 Guest are viewing this topic.

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Help. vlax-curve-getDistAtPoint Error (Real World Coordinate)
« Reply #15 on: January 27, 2018, 11:22:07 PM »
Well. I've been playing around with this bit of code to correct the issue with arced segments. It ALMOST works. That is - it finds the correct intersect point on a polyline with straight and arc segments (evidenced by the line drawn). However - for some reason the curve distance is not always returned, but works only intermittently. I cannot figure out why yet.

Code: [Select]
(defun c:VIS-HOR-STAIS ( /  sel pt spt1 spt2 ang rad pds int ent stais)
   (vl-load-com)
   (if (and
          (setq sel (entsel "\nSelect Alignment: "))
          (setq  pt (getpoint "\nSelect Point: "))
       )
      (if (setq spt1 (osnap (cadr sel) "cen")) ; If it's an arc segment in the polyline
         (setq  rad  (distance (osnap (cadr sel) "nea") spt1)
                ang  (angle pt spt1)
                pds  (- (distance pt spt1) rad)
                int  (polar pt ang pds)
                int  (if (osnap int "nea") (osnap int "nea") (polar pt ang (+ (distance pt spt1) rad)))
                ent  (car sel)
               stais (vlax-curve-getDistAtPoint ent (vlax-curve-getClosestPointTo ent (trans int 1 0)))
         )
         (setq spt1 (osnap (cadr sel) "nea") ; get the nearest point to the entity pick
               spt2 (osnap spt1 "end") ; get the nearest endpoint to the entity pick
               ang  (angle spt1 spt2) ; determine the angle of the segment.
               ; get the intersection with the point and the curve, at perp. angle.
               int  (inters spt1 spt2 pt (polar pt (+ ang (/ pi 2)) 1.0) nil)
               int  (if (osnap int "nea") int spt2) ; If no object is found at the int, set to the nearest endpoint found.
               ent  (car sel)
              stais (vlax-curve-getDistAtPoint ent (vlax-curve-getClosestPointTo ent (trans int 1 0)))
         )
      )
   )
   (command "._line" "_non" int "_non" pt "")
   (if stais
       (princ (strcat "\n. Station: " (rtos stais 2 3) " m"))
       (princ "\nError: Distance not found.")
   )
   (princ)
)

I know there are probably more complicated and reliable ways to do this, but I was attempting to keep it simple. I'm sorry but I don't have the knowledge to write anything more complex in a reasonable time. :-( Perhaps one of the other Guru's here could write something faster than I could, or figure out why my above code is not getting the curve distance reliably.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

rayakmal

  • Newt
  • Posts: 53
Re: Help. vlax-curve-getDistAtPoint Error (Real World Coordinate)
« Reply #16 on: January 28, 2018, 01:48:21 AM »
Well. I've been playing around with this bit of code to correct the issue with arced segments. It ALMOST works. That is - it finds the correct intersect point on a polyline with straight and arc segments (evidenced by the line drawn). However - for some reason the curve distance is not always returned, but works only intermittently. I cannot figure out why yet.

I know there are probably more complicated and reliable ways to do this, but I was attempting to keep it simple. I'm sorry but I don't have the knowledge to write anything more complex in a reasonable time. :-( Perhaps one of the other Guru's here could write something faster than I could, or figure out why my above code is not getting the curve distance reliably.

No worry and don't be sorry, buddy. Your help is very much appreciated.

I know AutoCAD behaves differently under this circumstances. Try to move any object on the testing drawing to 0,0, they won't move. Also you can try to copy, it won't work either. I tried several visual Lisp routine from John Burke and Lee Mac (*Polyline routine), their codes don't always work either. In this situation, where the real world coordinates are so big, I was forced to re-wrote my codes back to the 'standard lisp', involved some geometry, but I found out it's more robust and dependable. Once again, thanks for all your help.

rayakmal

  • Newt
  • Posts: 53
Re: Help. vlax-curve-getDistAtPoint Error (Real World Coordinate)
« Reply #17 on: January 31, 2018, 10:08:27 AM »
I think I've found the cuplrit. If I convert the Polyline into LwPolyline, no more error in my code.

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Help. vlax-curve-getDistAtPoint Error (Real World Coordinate)
« Reply #18 on: January 31, 2018, 10:16:11 AM »
I think I've found the cuplrit. If I convert the Polyline into LwPolyline, no more error in my code.

Excellent. Yes - I just tested the code again after converting and it works perfectly. Great Catch!

Still is a bit annoying however that the "vlax-curve.." functions do not work consistently with Heavy Polylines.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt