Given a vector, how can I limit other vectors passing through its perpendicular?

I have an vector in space that I want to use to 'restrict' other vectors, but I've no idea how. Since I don't know how to explain this using math terms, here's a picture:

The blue line represents the vector that will 'restrict' the other vectors.

Green lines represent other vectors that should be 'restricted'.

The red line is perpendicular to the 'restricting' vector (blue line) - green lines passing through this line should be 'restricted' to this line.

For more clarification: If the limiting vector was something like $(0, 5)$, all other vectors would have their $Y$ values limited to $(-\infty, 5]$, but it's not that simple when the blue vector is not axis-aligned.

• Do you mean to say that green lines should not cross the red line? – Hurkyl Mar 10 '18 at 6:07

There are a couple of ways to interpret what you mean by “limiting” a vector, but based on your example of $(0,5)$ as the limiter, it looks like you want to trim the component that’s parallel to the limiting vector. This is easily done by projecting onto the limiter.

Let $\mathbf v$ be the “limit” vector. Given a vector $\mathbf x$ that is to be trimmed, first compute the scalar projection $p$ of $\mathbf x$ onto $\mathbf v$: $$p = {\mathbf x\cdot\mathbf v \over \|\mathbf v\|}.$$ If $p\le\|\mathbf v\|$ then there’s nothing to do. Otherwise, decompose $\mathbf x$ into its components $\mathbf x_\parallel$ and $\mathbf x_\perp$ parallel and orthogonal, respectively, to $\mathbf v$, and replace $\mathbf x_\parallel$ with $\mathbf v$. The orthogonal component is $$\mathbf x_\perp = \mathbf x - {p\over\|\mathbf v\|}\mathbf v,$$ the orthogonal rejection of $\mathbf x$ from $\mathbf v$ and so the trimmed vector is $$\mathbf x_\perp+\mathbf v = \mathbf x + \left(1 - {p\over\|\mathbf v\|}\right)\mathbf v = \mathbf x + \left(1-{\mathbf x\cdot\mathbf v \over \mathbf v\cdot\mathbf v}\right)\mathbf v.$$ You can even combine this expression with the test if you like: $$\mathbf x + \min\left(0,1-{\mathbf x\cdot\mathbf v \over \mathbf v\cdot\mathbf v}\right)\mathbf v$$

If instead you just want to shorten $\mathbf x$ without changing its direction, simply multiply the entire vector by ${\|\mathbf v\|\over p}$ without performing the above decomposition.

• The last bit was exactly what I was looking for. I was intending to shorten x without changing its direction. Your full answer will still definitely help me in the future, though. I actually didn't understand what ||v|| meant, but was able to find a quick explanation here. – Jeffrey Cordova Mar 10 '18 at 16:54
• As a note, in order to shorten x, I had to divide x by p/∥v∥, not multiply. Is this what you intended? I may have implemented the formula wrong - but I seem to be getting the correct values by dividing. – Jeffrey Cordova Mar 10 '18 at 17:00
• @JeffreyCordova Sorry about that. Corrected. – amd Mar 10 '18 at 18:37
• @JeffreyCordova If you’re coding this, you can save yourself a square root operation: ${p\over\|\mathbf v\|} = {\mathbf x\cdot\mathbf v\over\mathbf v\cdot\mathbf v}$ and the condition $p\le\|\mathbf v\|$ is equivalent to $\mathbf x\cdot\mathbf v\le\mathbf v\cdot\mathbf v$ or ${\mathbf x\cdot\mathbf v\over\mathbf v\cdot\mathbf v}\le 1$. – amd Mar 10 '18 at 18:55

I think you are trying to describe the following:

Let $O$ denote the origin. Suppose you're given a (blue) point $P$. Let $\ell$ be the (red) line through P that is perpendicular to $\overline{OP}$.

If I'm given another (green) point $Q$, how do I tell whether $O$ and $Q$ are on the same side of $\ell$?

For the sake of arithmetic, I will treat points as vectors. I will assume further that $P \neq O$.

• $Q$ lies on $\ell$ if and only if $(Q-P) \cdot P = 0$
• Two points $Q$ and $R$ are on the same side of $\ell$ if and only if $(Q-P) \cdot P$ and $(R-P) \cdot P$ have the same sign.

In particular, $Q$ and $O$ are on the same side of $\ell$ if and only if $(Q-P) \cdot P$ is negative. Or equivalently, when $Q \cdot P < P \cdot P$

Here, $\cdot$ means the dot product of vectors. One way to prove these formulas are correct is:

• Formulas involving dot products remain true if you rotate a diagram around the origin
• These formulas are true in the case you understand: when $P$ lies on the $y$ axis.

As an aside, how I personally arrived at these formula is that I know these sorts of questions usually reduce to checking the results of a linear equation.

I determined the formula that gives zero if and only if a point lies on the given line. Then the points that give positive values for this formula all lie on one side of the line, and the points that give negative values for this formula lie on the other side.

To determine that formula, let $v$ be perpendicular to $P$. Then $Q$ lies on $\ell$ iff $Q = P + kv$ for some scalar $k$. Taking the dot product with $P$ eliminates the unknown constant; the equation reduces to $Q \cdot P = P \cdot P$. Since $Q \cdot P = P \cdot P$ is a single (scalar) linear equation in the variable $Q$, its solution space is one dimensional, and thus is exactly the line $\ell$.

• Thank you for your answer, the clarification for the dot product saved me a lot of time - and hair. Although your answer was helpful, I was intending to 'trim' green vectors that run passed the red line. – Jeffrey Cordova Mar 10 '18 at 16:47