# Find point on line withv given start point, distance, and line equation

I have line equation $$Ax +By + C = 0.$$

I have start point (on this line): $P_0 = (X_0, Y_0)$. I have distance $d$ too.

I need find point $P_2$ with distance $d$ from $P_0$ and placed on this line. I know that we have 2 points with this distance. But how calculate? I need some programmatic solution.

• Intersect the circle with center $P$ and radius $d$ with the line. – Jack D'Aurizio Dec 20 '14 at 14:22
• Hint: what are the coordinates $x$ and $y$ if the point is on the line? How to compute distance? Solve an equation. – Sigur Dec 20 '14 at 14:22
• @JackD'Aurizio that is great idea but i have problem to implement this as a programming method. – m___b Dec 20 '14 at 14:27

From the equation $Ax+By+C = 0$, find the slope of the straight line: $$A\cdot{\Delta x} + B\cdot{\Delta y} = 0$$ As long as $B\ne 0$, $\Delta y = -\frac AB \Delta x$. Also it is known that $$d = \sqrt{(\Delta y)^2 + (\Delta x)^2} = \left|\Delta x\right| \sqrt{1+\frac {A^2}{B^2}}$$ So $\Delta y$ and $\Delta x$ can be solved (and there are two pairs of $\Delta x$ and $\Delta y$).

If $B=0$, the straight line is a vertical line and $\Delta y$ is pretty easy to solve; but using similar reasoning, $\Delta x = 0$ and then $$d = \sqrt{(\Delta y)^2 + (\Delta x)^2} = \left|\Delta y\right| \sqrt{1+0}$$

• could you show me your idea on some example? I have some problem with understand yout equations – m___b Dec 20 '14 at 14:40
• great, really thanks , i think only which solution is better , your or @Martin R – m___b Dec 20 '14 at 14:55

$(A, B)$ is a normal vector for the line, therefore $v = (-B, A)$ is a direction vector and you get all points on the line with

$$(x, y) = P_0 + t \, v = (X_0, Y_0) + t (-B, A), \quad t \in \mathbb R.$$

Now choose $t$ such that the length of $t(−B,A)$ is equal to the given distance $d$, this gives the two points

$$(X_2, Y_2) = (X_0, Y_0) \pm \frac d{\sqrt { A^2 + B^2}} (-B, A) \quad .$$