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

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #30 on: September 28, 2010, 12:20:20 PM »
Okay Gile.  I think I understand your code now.  Here it goes.

The dot product will give you angle and magnitude, but since you are using it on two unit vectors, all you get is the angle ( or cosine of the angle ) between the view direction and the normal of the plane.
Code: [Select]
(setq scl (DotProduct nor dir))
Then you make sure that it isn't perpendicular.
Code: [Select]
(not (equal 0. (setq scl (DotProduct nor dir))))
Then you get the dot product of the ' normal of the plane ' and the vector ' from a point on the plane to the point selected '.  This time one is not a unit vectors, so you get the magnitude of the vector also.
Code: [Select]
(DotProduct nor (mapcar (function -) pt org))
Then you divide the previous step, by the first step, so that you get the magnitude ( distance in this case ) from the plane to the point selected.  I had a question here though.  Does the new scalar include an angle also?  or is only the magnitude left?  I would think a partial angle would still be represented in the scalar, unless the angles are equal ( angle between view direction and normal of plane, and angle of normal of plane and angle from point on plane to selected point ).
Code: [Select]
(setq scl (/ (DotProduct nor (mapcar (function -) pt org)) scl))
Since you have a vector ' dir ' and a magnitude ' sc1 ', you multiple them, so that you can get the vector that represents the projection of the selected point to the plane.  But you need the magnitude to go in the opposite direction, so you need a negative magnitude first.
Code: [Select]
(mapcar (function (lambda (x) (* x (- scl)))) dir)
Now that we have a vector that represents the path the point will take to project itself onto the plane, all that is left to do is add the point and the vector.
Code: [Select]
(mapcar (function +) pt (mapcar (function (lambda (x) (* x (- scl)))) dir))
I hope I understood correctly.  Thanks again Gile.  This was a good learning exercise for me.  Not sure if I would have gotten it as quickly as I did without your code to show it.
Tim

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

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #31 on: September 28, 2010, 02:00:14 PM »
As far as I can read English, you seem to have a good understanding of the method.

It works even the vectors aren't unit vectors.

It's the way used to calculate the intersection between a line (unbounded) and a plane (from here):

Code: [Select]
;;; VXV Returns the dot product of two vectors

(defun vxv (v1 v2)
  (apply '+ (mapcar '* v1 v2))
)

;;================================================================;;

;; ILP (gile)
;; Returns the intersection point between the line defined by two points
;; and the plane defined by a point and a normal vector
;;
;; Arguments
;; p1 et p2 : 3d points which defines the line
;; org : any point of the plane
;; nor : the normal vector of the plane

(defun ilp (p1 p2 org nor / scl)
  (if (and
(/= 0 (setq scl (vxv nor (mapcar '- p2 p1))))
(setq scl (/ (vxv nor (mapcar '- p1 org)) scl))
      )
    (mapcar (function (lambda (x1 x2) (+ (* scl (- x1 x2)) x1)))
    p1
    p2
    )
  )
)
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #32 on: September 28, 2010, 02:40:09 PM »
Thanks again Gile.  Now I'll see if I understand that code better now.   :-D
Tim

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

Please think about donating if this post helped you.

ScottBolton

  • Guest
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #33 on: September 29, 2010, 02:54:16 AM »
Luis / Gile,

 :-o What software are you using to create your gif?

S

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #34 on: September 29, 2010, 07:26:41 AM »
Luis / Gile,

 :-o What software are you using to create your gif?

S

Camtasia studio
Speaking English as a French Frog

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Issue with ' vlax-curve-getClosestPointTo '
« Reply #35 on: September 29, 2010, 11:24:55 AM »
Here is the link to the final code that this post relates to.
Copy along curve [ http://www.theswamp.org/index.php?topic=35097.0 ]
Tim

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

Please think about donating if this post helped you.