Find the Point with specific distance to two line segments

198 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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

1
On

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