[Math] Creating a bounding box for 2 points with a custimizable width

geometry

So I'm a little lost on the math aspect if what I need to do.

Basically, I have 3 points.

Point A, Point B, Point C.

I need to find out if point C is inbetween a line from Point A to Point B. But… the caveat is that I at the same time need to make the line "wider" from Point A to B.

So I'm guessing I need to first create a bounding box that surrounds A->B? Than check if I'm within the bounding box?

How do I go about creating that box..

A and B can negative or positive on the grid, and the "distance" of the box is changable as well.

I'm hoping this picture illustrates it better. The distance is the total given, so half would go 1 direction, half the other.

So basically, even if I can just get those 4 points of the box, I can do the simple check to see if C is within.

http://i.stack.imgur.com/OUd9x.png

Best Answer

you have:

  • point $A$ with coordinates $(x_a,y_a)$
  • point $B$ with coordinates $(x_b,y_b)$

Vector $\overrightarrow v$ describes the line between $A$ and $B$ $$\overrightarrow v=[x_a-x_b, y_a-y_b]$$ Vector $\overrightarrow w$ is perpendicular to vector $\overrightarrow v$ and describes the direction of 'distance'. $$\overrightarrow 0 = \overrightarrow v \bullet \overrightarrow w$$ $$\overrightarrow w = [w_x,w_y]$$ Now I wan't to calculate the unit vector of $\overrightarrow w$ $$w= \sqrt{w_x^2+w_y^2}$$ $$\overrightarrow w_u =[\frac{w_x}{w},\frac{w_y}{w}] = [w_{ux},w_{uy}]$$

With the unit vector of the direction of distance you're able to calculate how much a point would move in x- and y direction if you would add the distance. ($d$ = distance) $$d_x = \frac{d}{2} \times w_{ux}$$ $$d_y = \frac{d}{2} \times w_{uy}$$

With this precalculus you can now calculate your $4$ points:

  • Point $1 = [x_a+d_x, y_a+d_y]$
  • Point $2 = [x_a-d_x, y_a-d_y]$
  • Point $3 = [x_b+d_x, y_b+d_y]$
  • Point $4 = [x_b-d_x, y_b-d_y]$
Related Question