Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute two points, each on a line, equally distant from a given point?

I have a set of five points: a, b, c, d, e. I want to compute the corners Q, R of the triangle below. The tricky part is that the distances between Q-e and R-e must be equal.

enter image description here

I'm using the formula for a straight line L(x)=kx+m like this cute webpage shows. The first intersecting point P is calculated as follows.

double k_ab = (b.Y - a.Y) / (b.X - a.X);
double m_ab = a.Y - k_ab * a.X;
double k_cd = (d.Y - c.Y) / (d.X - c.X);
double m_cd = c.Y - k_cd * c.X;

double p = (m_cd - m_ab) / (k_ab - k_cd);
Point P = new Point(p, k_ab * p + m_ab);

Then, I get stuck. Since I don't know the exact x coordinate for the point Q, I have to use it as a variable. Even on paper I get brain poofage because there's too much moving parts and subcomputation. I'm sensing that I've chosen a poor and inefficient approach to the problem, so if anybody has a suggestion how to reformulate the problem to make the solution more apparent, I'd be delighted.

like image 799
Konrad Viltersten Avatar asked Oct 29 '22 20:10

Konrad Viltersten


1 Answers

Here's how to find the x values of Q and R:

Let f(x) be the equation of the line that contains a and b.

Let g(x) be the equation of the line that contains c and d.

Then f(Q_x) - e_y == e_y - g(R_x), and Q_x - e_x == e_x - R_x

Let z = Q_x - e_x

To calculate z, solve f(e_x + z) - e_y = e_y - g(e_x - z), which is

k_ab * (e.x + z - a.x) + a.y - e.y = e.y - c.y - k_cd * (e.x - z - c.x)

k_ab * (e.x + z - a.x) + k_cd * (e.x - z - c.x) = 2 * e.y - a.y - c.y

k_ab * (e.x - a.x) + k_cd * (e.x - c.x) + k_ab * z - k_cd * z = "

z * (k_ab - k_cd) = 2 * e.y - k_ab * (e.x - a.x) - k_cd * (e.x - c.x) - a.y - c.y

So finally

z = (2 * e.y - k_ab * (e.x - a.x) - k_cd * (e.x - c.x) - a.y - c.y) / (k_ab - k_cd)

And Q_x = e_x + z and R_x = e_x - z. I'm sure you can figure the rest out from here.

Try it here

Example

like image 100
KoreanwGlasses Avatar answered Nov 28 '22 13:11

KoreanwGlasses