# How to move a point onto a line, but leave it alone if it is already on the line? [closed]

Let say I have a given point and a line. The point may be on the line or not. How to make sure that this line remains in place, while I need to move the point to the line, only if it is not on the line. See this image:

-

## closed as not a real question by BenjaLim, Henning Makholm, Leonid Kovalev, Chris Eagle, rschwiebAug 14 '12 at 16:59

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Could you perhaps rephrase the last two sentences? What do you mean by line always remaining on line and moving line only if it is not on line? – T. Eskin Apr 23 '12 at 11:52
@ThomasE., I have added an image – user960567 Apr 23 '12 at 11:58
What do you mean by "line remain on line"? – dtldarek Apr 23 '12 at 11:58
Why should we expect that the point won't remain on the line if you place it on the line? Your question implies some dynamical process, but you don't provide any context. -1 – Raskolnikov Apr 23 '12 at 12:07
Are you looking for the general formula for a general line through a fixed point? – Mark Bennet Apr 23 '12 at 12:23

In case you are asking how to project point onto a line, then there is a simple formula for an orthogonal projection which can be done as follows. Let $v$ be the vector denoting the line, then

$$x' = \frac{\langle v, x \rangle}{\langle v, v \rangle}\cdot v$$

where

$$\langle a, b \rangle = \sum_i a_i\cdot b_i$$

is the standard scalar product. In 2D the whole formula will look like below:

let $P = (P_x, P_y)$ and $Q = (Q_x, Q_y)$ will be two points the line passes through, then $v = P-Q = (P_x-Q_x, P_y-Q_y)$ and the projection of $R = (R_x, R_y)$ denoted as $R' = (R_x', R_y')$ can be calculated by the formula:

$$(R_x', R_y') = \frac{(R_x-Q_x)\cdot v_x + (R_y-Q_y)\cdot v_y}{v_x^2+v_y^2}\cdot(v_x, v_y) + (Q_x, Q_y).$$

Of course this can be easily generalized to higher dimensions. Cheers!

-
Yes. Thanks. Why so many -ve votes. – user960567 Apr 23 '12 at 17:41