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

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #15 on: September 25, 2010, 09:59:02 PM »
I suspect you will need to change the UCS to match that of the object in order to relate the cursor to it.
Just guessing on my end. :-)
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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #16 on: September 26, 2010, 03:40:29 AM »
If I keep on understanding, the easiest way should be, as CAB said, to change the current UCS :
(command "_.ucs" "_object" ent)

An other way is to project the point returned by (cadr grList) on the entity plane about the current view direction.
Here's an example:

Code: [Select]
(defun c:Test (/ Sel Ent Norm vDir StPt Ext GrList tempPt projPt)

  (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)))
    vDir (trans '(0. 0. 1.) 2 0 T)
  )
  (while (and (not Ext) (setq GrList (grread T 13 1)))
    (cond
      ((equal (car GrList) 5)
       (setq projPt (ProjectPointOnPlane
              (trans (cadr grList) 1 0)
              vDir
              stPt
              norm
            )
         tempPt (vlax-curve-getClosestPointTo
              Ent
              projPt
              nil
            )
       )
       (redraw)
       (grvecs
     (list
       1
       (trans StPt 0 1)
       (trans tempPt 0 1)
       2
       (trans StPt 0 1)
       (trans projPt 0 1)
       2
       (trans projPt 0 1)
       (trans tempPt 0 1)
     )
       )
      )
      ((equal (car GrList) 3)
       (entmake
     (list '(0 . "LINE") (cons 10 tempPt) (cons 11 projPt))
       )
      )
      (
       (and
     (equal (car GrList) 2)
     (member (cadr GrList) '(13))
       )
       (setq Ext T)
      )
      ((member (car GrList) '(11 25))
       (setq Ext T)
      )
    )
  )
  (redraw)
  (princ)
)

;; ProjectPointOnPlane (gile)
;; Returns the projected point on the specified plane
;;
;; Arguments
;; pt: the point to be projected
;; dir: the projection direction vector
;; org: a point on the projection plane
;; nor: the projection plane normal vector

(defun ProjectPointOnPlane (pt dir org nor / scl)
  (if (and
(/= 0 (setq scl (DotProduct nor dir)))
(setq scl (/ (DotProduct nor (mapcar '- pt org)) scl))
      )
    (mapcar '+ pt (mapcar '(lambda (x) (* x (- scl))) dir))
  )
)

;; DotProduct (gile)
;; Returns the dot product (scalar product) of two vectors
;;
;; Arguments : two vectors

(defun DotProduct (v1 v2) (apply '+ (mapcar '* v1 v2)))
« Last Edit: September 26, 2010, 01:37:55 PM by gile »
Speaking English as a French Frog

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #17 on: September 26, 2010, 12:37:11 PM »
I still don't know what it is the idea  :lol: but, end up doing what I mentioned about arx [ if (pCurve->getClosestPointTo(pickPoint, vDisplay, pClosest) != Acad::eOk) return; ]
Have a look at the image, if that is not what you are trying to do well... :-P

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #18 on: September 26, 2010, 01:56:08 PM »
Corrected a mistake in the ProjectPointOnPlane function.

It seems to work as expected (as Luis's) now.
Speaking English as a French Frog

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #19 on: September 26, 2010, 02:22:40 PM »
I think, I was able to figure out the name in lisp from the arx function, and did the corrections (and no need of arx usage or c# that i did):
Code: [Select]
(defun c:Tester2 ( / 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))))

  (setq wcs 0)
  (setq ucs 1)
  (setq dcs 2)

;;;  (trans pt ucs wcs 0)

(setq vecDCSNormal (list 0 0 1))
  ;(trans vecDCSNormal dcs wcs 1)

    (while (and (not Ext) (setq GrList (grread T 13 1)))
        (cond
            ((equal (car GrList) 5)
                (setq tempPt (vlax-curve-getClosestPointToProjection Ent (trans (cadr GrList) 1 0 0) (trans vecDCSNormal dcs wcs 1)))
                (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-getClosestPointToProjection Ent (trans (cadr GrList) 1 0 0) (trans vecDCSNormal dcs wcs 1)))
            )
            (
                (and
                    (equal (car GrList) 2)
                    (member (cadr GrList) '(13))
                )
                (setq Ext T)
            )
            ((member (car GrList) '(11 25))
                (setq Ext T)
            )
        )
    )
    (redraw)
    (princ)
) [code]
[/code]

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #20 on: September 26, 2010, 05:37:47 PM »
Worked like a charm gile. 8-)


Close Luis but still will not track around the entire object.

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.

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #21 on: September 26, 2010, 07:20:16 PM »
Close Luis but still will not track around the entire object.
Thank you Alan, I tested both routines on the same drawing(Tim's) and did not noticed any difference - but must be me :)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #22 on: September 27, 2010, 11:11:41 AM »
Thanks you both, Gile and Luis.  They both seems to work as advertised.  Now I just need to study the code, and see how you guys were able to do it.
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #23 on: September 27, 2010, 12:02:29 PM »
Close Luis but still will not track around the entire object.
Thank you Alan, I tested both routines on the same drawing(Tim's) and did not noticed any difference - but must be me :)
Just tried again and no joy. Must be my version of ACAD2000.
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.

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #24 on: September 27, 2010, 12:05:05 PM »
:-o
Never use that version, could be.

Just tried again and no joy. Must be my version of ACAD2000.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #25 on: September 27, 2010, 12:21:00 PM »
It must be Alan, because from looking at the codes, they are both doing the same thing, except Gile is doing the translation himself, while Luis is letting Acad's built in functions handle the translation.  If that is the case, then maybe I'll use Gile's solution, since it works better with older versions of Acad.

Side note:  I was trying to use the view direction system variable ' ViewDir '.  Never thought to translate the normal view direction like both Gile and Luis did.  Very smart.  Now off to study the method behind projecting a point onto a plane.

Thanks again guys!
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 #26 on: September 27, 2010, 12:27:35 PM »
I'm glad you have your problem solved Tim.

I tried to stay within the built-in functions, but as you if you are going to support previous versions, then Gile's it is a better approach.

Side note:  I was trying to use the view direction system variable ' ViewDir '.  Never thought to translate the normal view direction like both Gile and Luis did.  Very smart.  Now off to study the method behind projecting a point onto a plane.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #27 on: September 27, 2010, 02:34:51 PM »
Quote
from looking at the codes, they are both doing the same thing

I don't think so.
Luis uses the vlax-curve-getClosestPointToProjection function which project the curve to the view plane, then, calculates the closest point from the cursor (UCS plane) to the projected curve and project this point back to the curve.

The way I use is to project the cursor point on the curve plane along the view direction (which may be a non orthogonal projection) and returns the closest point from this point. It works the same as if the current UCS plane was the same as the the curve plane.

In this little video I first run my 'test' command which draws a red line between the projected point and the returned point. Then I run Luis's 'tester2' in which I add an expression to draw a green line between the cursor point and the returnd point.
Code: [Select]
[...]
((equal (car GrList) 3)
       (setq Pt (vlax-curve-getClosestPointToProjection
  Ent
  (trans (cadr GrList) 1 0 0)
  (trans vecDCSNormal dcs wcs 1)
)
       )
       [color=red](entmake
(list '(0 . "LINE") (cons 10 Pt) (cons 11 (trans (cadr GrList) 1 0)))
       )[/color]
      )
[...]
Speaking English as a French Frog

LE3

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #28 on: September 27, 2010, 03:08:01 PM »
Nice demo - gile.

Thanks!

edit: added the note below:
When I grow up, I want to be like you [intelligent] (I know it will take me quite some years)

:)
« Last Edit: September 27, 2010, 03:55:52 PM by LE »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #29 on: September 27, 2010, 03:45:12 PM »
Nice explanation Gile.
Tim

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

Please think about donating if this post helped you.