# Perpendicular coordinate from block to line

## Recommended Posts

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 ?????)

```

##### Share on other sites

Excuse me!

Already nailed it with the 'inters' function.

##### Share on other sites

Also look into vlax-curve-getclosestpointto.

##### Share on other sites

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)
)
)```

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)
)
)```

```(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 on other sites

Nice Lee Mac,

Ill give it a try.

##### Share on other sites

This program can get the vertical coordinate point xy4

```(defun per4 (xy1 xy2 xy3 )

(setq ang (angle   xy1 xy2)
ptm (polar   xy3 (+ (* 0.5 pi) ang) 0.1)
xy4 (inters  xy1 xy2 xy3 ptm nil)
)
)```

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.