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

  • $\begingroup$ Sorry, I really don't understand what you're asking. Can you clarify? $\endgroup$ – Billy Aug 27 '11 at 9:56
  • $\begingroup$ 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? $\endgroup$ – Ilmari Karonen Aug 27 '11 at 18:01

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

  • $\begingroup$ Yes, you fully understand what I want. Can you help with a formula? $\endgroup$ – 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.

  • $\begingroup$ 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? $\endgroup$ – Paul Grime Jan 12 '18 at 12:24
  • $\begingroup$ @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. $\endgroup$ – 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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