# Checking whether a point lies on a wide line segment

I know how to define a point on the segment, but I have this piece is a wide interval. The line has a width.

I have $x_1$ $y_1$, $x_2$ $y_2$, width and $x_3$ $y_3$

$x_3$ and $x_4$ what you need to check.

perhaps someone can help, and function in $\Bbb{C}$ #

• Sorry, I really don't understand what you're asking. Can you clarify? – Billy Aug 27 '11 at 9:56
• I edited the title to make it more descriptive, but I couldn't really make enough sense of the question itself to edit it. I suspect it means something like this: I have three points on the plane, $A=(x_1,y_1)$, $B=(x_2,y_2)$ and $C=(x_3,y_3)$. How do I check whether $C$ lies in the rectangle formed by moving the line segment $AB$ up to distance $w$ (or $w/2$?) in either direction along its normal? – Ilmari Karonen Aug 27 '11 at 18:01

## 3 Answers

Trying to understand your question, perhaps this picture might help. You seem to be asking how to find out whether the point $C$ is inside the thick line $AB$.

You should drop a perpendicular from $C$ to $AB$, meeting at the point $D$. If the (absolute) length of $CD$ is more than half the width of the thick line then $C$ is outside the thick line (as shown in this particular case).

If the thick line is in fact a thick segment, then you also have to consider whether $D$ is between $A$ and $B$ (or perhaps slightly beyond one of them, if the thickness extends further).

• Yes, you fully understand what I want. Can you help with a formula? – Mediator Aug 27 '11 at 10:45

Assuming @Henry's picture summarizes the question asked, for a given thickness $T$ a necessary and sufficient condition is given by the following inequalities: $$0\le\overrightarrow{AC}\cdot\overrightarrow{AB}\le AB^2,\qquad\qquad AB^2AC^2\le T^2AB^2+\left(\overrightarrow{AC}\cdot\overrightarrow{AB}\right)^2.$$ The first condition ensures that the projection of $C$ on the line $(AB)$ lies between $A$ and $B$ and the second condition ensures that the distance between $C$ and the line $(AB)$ is at most $T$.

To prove this, note that $\overrightarrow{AC}$ must be $\overrightarrow{AC}=u\overrightarrow{AB}+t\overrightarrow{N}$ with $0\le u\le 1$, $t^2\le T^2$ and $\overrightarrow{N}$ a unitary vector orthogonal to $\overrightarrow{AB}$ and try to express the conditions on $u$ and $t$ in terms of $\overrightarrow{AC}$, $\overrightarrow{AB}$, their norms $AC$ and $AB$, and their scalar product $\overrightarrow{AC}\cdot\overrightarrow{AB}$ only.

• Using the image supplied by @henry, is thickness, T, the distance along the line DC to where the rectangle ends? Or is thickness, T, twice that distance? – Paul Grime Jan 12 '18 at 12:24
• @PaulGrime Could be either one, depending on the setting where one encounters the notion. Why do you ask? If you are referring to the context of my post then the definition of $T$ is explicitely written in the post. – Did Jan 12 '18 at 13:28

Please check "Line defined by two points" section of https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line

From there, it is easy to derive the C# function:

double distOfLineDefinedBy2PointsAndPoint(double x1, double y1, double x2, double y2, double x3, double y3) {
return Math.Abs((y2 - y1) * x3 - (x2 - x1) * y3 + x2 * y1 - y2 * x1) /
Math.Sqrt(Math.Pow(y2 - y1, 2) + Math.Pow(x2 - x1, 2));
}


Now, you can use the result of this function and compare it to half of the width.