Jump to content
Aftertouch

Perpendicular coordinate from block to line

Recommended Posts

Aftertouch

Hello all,

 

Got myself into something again...

 

I got a line from point A to point B.

There is a block at point C. How can i get the coordinate on that line,  perpendicular from the block?

lets say....

 


(setq xy1 (list 1 1 0))

(setq xy2 (list 2 3 0))

(setq xy3 (list 1.5 1.6 0))

(setq xy4 ?????)

 

image.png.5aac03491418780ae79b7b1030c8309f.png

Share this post


Link to post
Share on other sites
Aftertouch

Excuse me!

Already nailed it with the 'inters' function. 🙂

Share this post


Link to post
Share on other sites
Lee Mac

Alternatively from here:

;; Project Point onto Line  -  Lee Mac
;; Projects pt onto the line defined by p1,p2

(defun LM:ProjectPointToLine ( pt p1 p2 / nm )
    (setq nm (mapcar '- p2 p1)
          p1 (trans p1 0 nm)
          pt (trans pt 0 nm)
    )
    (trans (list (car p1) (cadr p1) (caddr pt)) nm 0)
)

Which could also be written:

(defun LM:projectpointtoline ( pnt pt1 pt2 )
    (   (lambda ( vec ) (trans (reverse (cons (caddr (trans pnt 0 vec)) (cdr (reverse (trans pt1 0 vec))))) vec 0))
        (mapcar '- pt1 pt2)
    )
)

For your case:

(setq xy1 '(1.0 1.0 0.0)
      xy2 '(2.0 3.0 0.0)
      xy3 '(1.5 1.6 0.0)
      xy4  (LM:projectpointtoline xy3 xy1 xy2)
)

 

Edited by Lee Mac

Share this post


Link to post
Share on other sites
Aftertouch

Nice Lee Mac,

 

Ill give it a try. 🙂

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×