Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}$ #

share|cite|improve this question
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
up vote 3 down vote accepted

Trying to understand your question, perhaps this picture might help.

point line

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).

share|cite|improve this answer
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.

share|cite|improve this answer

Please check "Line defined by two points" section of

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.