Author Topic: Issue with ' vlax-curve-getClosestPointTo '  (Read 13053 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Issue with ' vlax-curve-getClosestPointTo '
« on: September 24, 2010, 12:28:16 PM »
With the sample code and drawing you can see that on the candy cane looking object that ' vlax-curve-getClosestPointTo ' does not return the closest point along the object.  I was wondering if anyone else has seen this, and if there is a way to fix it?

The two yellow lines represent the start point of the curve to the cursor location, then cursor location to where ' vlax-curve-getClosestPointTo ' is selecting the point.
The red line is just start point of the curve to the point returned by ' vlax-curve-getClosestPointTo '.

You will notice that on the other objects in the drawing, besides the solid, the lines are shown correctly.  If you change the UCS to world, and the run the program, then it will show correctly on the candy cane, but not the other two.  So now I'm back to the original section in the post.  I have tried ' trans 'ing the points different ways, but nothing I have thought of has worked.

Thanks.

Code: [Select]
(defun c:Test ( / Sel Ent Norm StPt Ext GrList tempPt Pt )
   
    (setq Sel (entsel "\n Select candy cane looking object: "))
    (setq Ent (car Sel))
    (setq StPt (vlax-curve-getPointAtParam Ent (vlax-curve-getStartParam Ent)))
    (setq Norm (cdr (assoc 210 (entget Ent))))
    (while (and (not Ext) (setq GrList (grread T 13 1)))
        (cond
            ((equal (car GrList) 5)
                (setq tempPt (vlax-curve-getClosestPointTo Ent (trans (cadr GrList) 1 0) nil))
                (redraw)
                (grvecs
                    (list
                        1
                        (trans StPt 0 1)
                        (trans tempPt 0 1)
                        2
                        (trans StPt 0 1)
                        (cadr GrList)
                        2
                        (cadr GrList)
                        (trans tempPt 0 1)
                    )
                )
            )
            ((equal (car GrList) 3)
                (setq Pt (vlax-curve-getClosestPointTo Ent (trans (cadr GrList) 1 0) nil))
            )
            (
                (and
                    (equal (car GrList) 2)
                    (member (cadr GrList) '(13))
                )
                (setq Ext T)
            )
            ((member (car GrList) '(11 25))
                (setq Ext T)
            )
        )
    )
    (redraw)
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #1 on: September 24, 2010, 12:35:41 PM »
Don't have time to test your code Tim but I've had vlax-curve-getClosestPointTo problems with large drawings (with respect to coordinate extremes) to the extent I had to write my own version of said function because I could not rely on the native one. The problems I had were not related to non WCS scenarios. Hope you find a suitable solution quickly.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #2 on: September 24, 2010, 01:01:13 PM »
Thanks for the heads up Michael.  I'm studying vectors and stuff right now, so maybe I'll see if I can roll my own, if that is the only way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #3 on: September 24, 2010, 01:11:12 PM »
Hola Tim,

I recall doing more transformations for the getClosestPointTo(); in arx for a custom getCurveSnapAngle() function based on selected point on a curve object.... let me see if I can port the steps back to autocad lisp... as soon I get a chance (guess spent more time typing this :) )

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #4 on: September 24, 2010, 01:17:17 PM »
Thanks Luis.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #5 on: September 24, 2010, 01:36:54 PM »
Thanks Luis.

OK.... I see there are not the same arguments in ARX ... hmmm...

Did a quick try with a change on this line:
(setq tempPt (vlax-curve-getClosestPointTo Ent (cadr GrList) nil))

Can you tested?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #6 on: September 24, 2010, 01:40:55 PM »
That didn't work either Luis.

No problem.  I can do some more research into math ( have to re/learn things ), and see if I can roll my own, as I think that is going to be the only way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #7 on: September 24, 2010, 02:01:59 PM »
That didn't work either Luis.

No problem.  I can do some more research into math ( have to re/learn things ), and see if I can roll my own, as I think that is going to be the only way.
it is obvious that I do not know what you are trying to do, have a look at the image: (if I get a chance will try to play more later today...)

(will post another image this one looks weird....) - uploaded (as zips sorry non displayed right here) two look into any of both... is that the right output?
« Last Edit: September 24, 2010, 02:09:58 PM by LE »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #8 on: September 24, 2010, 02:08:30 PM »
I'm trying to track the cursor movement along the selected curve in any UCS.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #9 on: September 24, 2010, 02:16:05 PM »
Thanks for the heads up Michael.  I'm studying vectors and stuff right now, so maybe I'll see if I can roll my own, if that is the only way.

You're welcome Tim, I have every confidence you'll pen an elegant solution and will enjoy the process.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #10 on: September 24, 2010, 03:33:16 PM »
Thanks for the vote of confidence Michael.  Will post what I have, when I have it.

Luis,

Yours seems not to be working at all correctly.  I don't have a screen capture program that will output gif files, so I can't show you have it works on my screen, but it is better than that.  I will see what I can come up with.  Thanks for testing it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #11 on: September 24, 2010, 04:12:23 PM »
I see, sorry about that... the more older I get, the more I forget, or need more detailed explanations, to understand.........  :-(
Luis,

Yours seems not to be working at all correctly.  I don't have a screen capture program that will output gif files, so I can't show you have it works on my screen, but it is better than that.  I will see what I can come up with.  Thanks for testing it.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #12 on: September 25, 2010, 05:08:29 AM »
Hi Tim,

Maybe I misundertood the question (one more time) but...

I did some test with your code and IMO all is working as expected.
The point returned by (cadr grList) owns to the current UCS plane, if the curve construction plane is different than this one, the line between the cursor point and the closest point on curve neithe owns the curve plane nor to the current UCS one so it doesn't diplays perpendicular to the curve.

Try adding:
(entmake (list '(0 . "LINE") (cons 10 tempPt) (cons 11 (trans (cadr grList) 1 0))))
in the ((equal (car GrList) 3) ...) expression, pick some points then use rotate3d to see these lines against the curve.
Speaking English as a French Frog

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #13 on: September 25, 2010, 08:49:47 AM »
Great explanation gile.
I spent several hours trying to figure this out and had a general idea what was wrong but you have confirmed it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #14 on: September 25, 2010, 06:57:26 PM »
I did some test with your code and IMO all is working as expected.
The point returned by (cadr grList) owns to the current UCS plane, if the curve construction plane is different than this one, the line between the cursor point and the closest point on curve neithe owns the curve plane nor to the current UCS one so it doesn't diplays perpendicular to the curve.

I think you understand correctly, but I was trying to find a way to translate the point returned by grread, so that it would show up on the entity.  So I know that grread returns the point in the current UCS, which doesn't necessarily mean that is the CS of the view or the OCS of the object, so I was trying to find a way that I could translate the point shown, be the closest to the entity.  I hope that makes sense.  If not let me know and I will try and explain it a little better.

So I think my basic problem is trying to translate the point the cursor is at on the screen, to relate more to the entity correctly.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.