# Closest Point on 2D Implicit Line

Consider the infinite line, L in 2D consisting of all points p such that p.[0.3511 0.9263] = 6. Find the point on the line closest to (10,20). Find the point on the line closest to (4,3). Find the distance from the line to both of these points.

Hi, I was reading the book 3D Maths Primer for Graphics and Game Development. The book mention about 2 formulas but I don't know how to apply them.

Signed distance = d-q.n

q' = q + (d-q.n)n

for any point q, the point q' that is the closest point on L to q.

This is what I have tried,

Since the lines are parallel then the normal are the same so

q' = q + (6 - q(0.3511 0.9263))(0.3511 0.9263)

I'm stuck here.

-
Seen this? –  Ｊ. Ｍ. Nov 20 '11 at 9:46
Hi, I'm trying to link the given formula in solving this question but i can't solve it. –  Xavier Nov 20 '11 at 10:58
Can you please use math formatting for the formulas. And accept an answer as a solution soon. –  ja72 Apr 19 '12 at 17:21

If a line is given by $\vec{p}\cdot\vec{n}=d$ where $\vec{p}=(x,y)$ is a point on the line, then $\vec{n}$ is the unit normal vector to the line (perpendicular direction) and $d$ is the minimum distance to the origin. For your case you have $\vec{p}\cdot(0.3511,0.9263)=6$, but unfortunately $\vec{n}$ is not a unit vector here. To make it a unit vector you have

$$\vec{p}\cdot(0.3544,0.9351)=6.0569$$

with $\vec{n}=(0.3544,0.9351)$ and $d=6.0569$. The distance between the point P and the closest point to the line is the perpendicular projection of the difference between P and A where is any point on the line. I choose the point A with coordinates $\vec{a}=\vec{n}\,d=(2.1467,5.6637)$ representing the closest point of the line to the origin. The distance of P with the line is $r=\vec{n}\cdot(\vec{p}-\vec{a})$ or

$$r = \vec{n}\cdot\vec{p}-d$$

with $r = 16.189$ for P=(10,20).

The point P' closest to the line is offset from P by $r$, with the equation $\vec{p}'=\vec{p}-\vec{n}\,r = \vec{p}-\vec{n}(\vec{n}\cdot\vec{p}-d)$, or

$$\vec{p}' = \vec{p}-(\vec{n}\cdot\vec{p}-d)\vec{n}$$

with $\vec{p}'=(4.2621,4.8619)$

Here is the checks I did with GeoGebra.

So proceed similarly with point Q = (4,3) to get Q' and the distance between P' and Q' as 0.415

-

You've got a line $L:ax+by=c$ where $a,b,c$ are given.

You've got a point $P=(r,s)$.

You want the point $Q$ on $L$ closest to $P$. Let's call it $Q=(u,v)$.

You know $Q$ is on $L$, so $au+bv=c$.

You know the line from $P$ to $Q$ is perpendicular to $L$. Can you figure out the slope (EDIT: also known as the gradient) of the line from $P$ to $Q$ (slope of a line joining two given points)? Can you figure out the slope of $L$ (slope of a line, given an equation of the line)? Do you know the relation between the slopes of two perpendicular lines?

If you can answer all those questions, you get a second equation relating the two unknowns $u,v$. Can you solve a system of two equations in two unknowns?

-
HI, when you say slope do you mean the gradient? using y = mx + c? –  Xavier Nov 20 '11 at 14:13
When I say slope, I mean slope. But, yes, many people use gradient to mean what I mean when I say slope. –  Gerry Myerson Nov 20 '11 at 23:19