I have three Points $A(x0,y0), B(x1,y1), C(x2,y2)$ and a distance $d$. From those I want to calculate $D(x3,y3)$ which is in the center between $AB$ and $AC$ and has the specified distance to those line segments. Example

I attempted to use the answer from this Question and rearrange the formula for $d$ to get the parameter $t$ as a result: $$ \frac{d^2 *((y0-y1)^2+(x1-x0)^2)}{((y0-y1)(x3-x0)+(x1-x0)(y3-y0))^2}=t^2 $$ Where I need $D$ because of $x3$ and $y3$, which I then replaced with the vector $\frac{AB}{||AB||}+\frac{AC}{||AC||}$ because it should describe the same line. I did not use the center because if the vector $AD$ is in the center, then it should be enough to calculate this for one side.

For context, I am doing this to calculate this point for each point in the convex hull of a convex polygon. I am trying to create a smaller version of this polygon, where each point has the distance $d$ to the outer polygon edges.

This does not work as I wanted it to. Is there a better approach or did I forget something?

  • $\begingroup$ I think you’ve made this more complicated than it needs to be by trying to adapt the other method. For one thing, since you’ve got $t^2$, there’s the potential of getting two solutions, so you’ll need to reject one of them somehow. Instead, offset the lines $AB$ and $AC$ by $d$ in the appropriate direction and find their intersection. This can be done in homogeneous coordinates with a few cross products and a norm or two. $\endgroup$ – amd May 19 '17 at 23:55
  • $\begingroup$ The $t$ is actually enough as it is, because the scaled vector already has the correct sign. However your solution sounds great, I can get the offset direction with the center of the polygon and then calculate the rest. Thanks! $\endgroup$ – Asbestion May 20 '17 at 0:23
  • $\begingroup$ Does the distance to the lines have to be the shortest distance to the lines? If so then that distance must be to a perpendicular which makes the equations MUCH simpler. If not there are infinite possible solutions (an entire wedge section of the plane-- the area of two overlapping circles) $\endgroup$ – fleablood May 22 '17 at 16:03

Use vectors:

1) Vector from $(0,0)$ to $A(x_0,y_0)$: $\vec{a} =(x_0,y_0)$.

2) direction vector $\vec{s}$ pointing $\\$ from $A$ to $C$:

$\vec{s}$ = $(x_2- x_0,y_2 - y_0)$, normalized: $(1/||s||)\vec{s}$.

3) direction vector $\vec{t}$ pointing $\\$ from $A$ to $B$:

$\vec{t} = (x_1 - x_0, y_1 - y_0)$, normalized: $1/||t|| \vec{t}$.

Vector addition:

$ \vec{r}$ pointing from $(0,0)$ to $D(x_3,y_3)$:

$\vec{r}= \vec{a} + d(1/||s||) \vec{s} + d(1/||t||)\vec{t}$.


Assuming "distance from a point to a line" means "shortest distance for a point to a line" we knot that must be a perpendicular.

Let $m_1 = \frac {y_1 - y_0}{x_1 - x_0}$ be the slope of line 1 and $m_2 = \frac {y_2 - y_0}{x_2 - x_0}$ be the slope of line 2.

The equation of the line from $D= (x_3,y_3)$ to Line 1 will be $(y -y_3) = -\frac 1{m_1}(x - y_3)$.

Solve for $(\Delta x)^2 + (\Delta y)^2 = (\Delta x)^2 + (\frac 1{m_1} \Delta x)^2 = d^2$. We know $(x_3 - \Delta x, y_3 - \Delta y)$ must be on line 1 so:

Equation 1: $(y_0 - y_3 +\Delta y) = m_1(x_0 - x_3 + \Delta x)$

Similarly and the exact argument, solve for $(\delta x)^2 + (\delta y)^2 = (\delta x)^2 + (\frac 1{m_2} \delta x)^2 = d^2$. We know $(x_3 + \delta x, y_3 - \delta y)$ must be on line 2 so:

Equation 2: $(y_0 - y_3 + \delta y) = m_1(x_0 -x_3 + \delta x)$

Solve equation 1 and 2 for $x_3, y_3$.

  • $\begingroup$ The distance is supposed to be the orthogonal distance. Between the lines labeled $d$ and $AB$/$AC$ should be an 90° angle, I forgot to include that into the drawing. $\endgroup$ – Asbestion May 22 '17 at 19:23

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.