3
$\begingroup$

I've asked this question first on Stack Overflow (How to find position in pixels of intersection of two lines?) but it's actually a math question so I'm asking it here and I'll delete the SO one.

enter image description here

I have $3$ points $A$, $B$ and $C$ and I need to calculate point $D$ in the picture above, so I can draw that shorter line segment. We should have $AC\perp BD$.

It should be simple (high school difficulty), but I don't know how to solve it. Do I need to calculate the line equations that go through two point and then perpendicular line equation that go through a point and then intersection of two lines, or is there easiest way?

It seems that when the ratio is $4:3$ the point is in golden point but if ratio is different the point is in other place.

$\endgroup$

4 Answers 4

2
$\begingroup$

Say $\vert AD\vert=a, \vert AB\vert =b, \vert DC\vert =c$ and $\vert BC\vert =d$. Now, by Pythagoras' theorem $$\vert DB\vert^2=b^2-a^2=d^2-c^2.$$ This implies that $$b^2-d^2=a^2-c^2\\\frac{b^2-d^2}{a+c}=a-c.$$ Now add $a+c$ to both sides and divide by two:$$\frac{b^2-d^2}{2(a+c)}+\frac{a+c}{2}=a.$$ So now we know that $\vert AD\vert = a=\frac{b^2-d^2}{2(a+c)}+\frac{a+c}{2}$. Note that $b$, $d$ and $a+c$ can be derived from the coordinates of $A$, $B$ and $C$.

Can you take it from here?

$\endgroup$
1
$\begingroup$

Here are a couple more ways to solve this problem.

Since $D$ is on the line segment $AC$, we have $D=(1-\lambda)A+\lambda B$ for some $\lambda\in[0,1]$. We want $AC\perp BD$, which can be expressed as $(C-A)\cdot(D-B)=0$. Solve the resulting equation for $\lambda$ and check that $0\le\lambda\le1$ so that $D$ actually falls on the line segment.

Using homogeneous coordinates, the line $\overline{AC}$ is given by $A\times C$. We know that $AC\perp BD$, so from the point-slope equation for the line $\overline{BD}$, $(C-A)\cdot(X-B)=0$, we find that this line is represented by the vector $(x_C-x_A,y_C-y_A,(A-C)\cdot B)$. The intersection of these lines is given by the cross product of these two vectors. A simple range check then tells you whether or not the point thus found is between $A$ and $C$ as required. (N.B.: this use of cross products is equivalent to solving a system of linear equations using Cramer’s rule.)

$\endgroup$
1
  • $\begingroup$ In the first line, shouldn't it be $D = (1 - \lambda)A + \lambda C$ (i.e. using $C$ instead of $B$). $\endgroup$
    – a_guest
    Commented Jan 25, 2021 at 16:34
0
$\begingroup$

There are several ways to solve this problem.

Suppose the coordinates for the points $A$, $B$, and $C$ are given by $$ \begin{align*} A &=(a_1,a_2, a_3,\ldots, a_n), \\ B &=(b_1,b_2,b_3,\ldots, b_n), \mbox{ and }\\ C &=(c_1,c_2,c_3,\ldots, c_n). \\ \end{align*} $$ Then the position vectors for these points $A$, $B$, and $C$ are $$ \begin{align*} \vec{\mathcal{O}A} &=\langle a_1,a_2, a_3,\ldots, a_n\rangle , \\ \vec{\mathcal{O}B} &=\langle b_1,b_2,b_3,\ldots, b_n\rangle, \mbox{ and }\\ \vec{\mathcal{O}C} &=\langle c_1,c_2,c_3,\ldots, c_n\rangle, \\ \end{align*} $$ where $\mathcal{O}$ is the origin $(0,0,\ldots, 0)$. Let $$ \begin{align*} \vec{v_1}&=\vec{AC}=\langle c_1-a_1,c_2-a_2,\ldots, c_n-a_n \rangle \mbox{ and } \\ \vec{v_2}&=\vec{AB}=\langle b_1-a_1,b_2-a_2,\ldots, b_n-a_n \rangle. \\ \end{align*} $$ Then the vector obtained by projecting $\vec{AB}$ onto $\vec{AC}$ is given as $$ \text{proj}_{\vec{AC}}\vec{AB} = \text{proj}_{\vec{v_1}}\vec{v_2} = \dfrac{\vec{v_1}\cdot \vec{v_2}}{\vec{v_1}\cdot \vec{v_1}}\vec{v_1} =\vec{AD}. $$ So $\vec{\mathcal{O}D}=\vec{\mathcal{O}A}+\vec{AD}$, which gives the position vector for the point $D$.

$\endgroup$
0
$\begingroup$

Method 1

Let the coordinates be $A(x_1, y_1), B(x_2, y_2), C(x_3, y_3), D(x_4, y_4)$.

If $x_1 = x_3$, $AC$ is vertical and $D \equiv (x_1, y_2)$.

If $y_1 = y_3$, $AC$ is horizontal and $D \equiv (x_2, y_1)$.

If neither is the case, the slope of line $AC$ is given by $m = \dfrac{y_3 - y_1}{x_3 - x_1}$ and equation of (extended) line $AC$ is $\dfrac{y - y_1}{x - x_1} = m \iff y - mx = y_1 - m x_1$.

Since $BD$ is perpendicular to $AC$, the slope of (extended) line $BD$ must be $- \dfrac{1}{m}$ and the equation is given by $y + \dfrac{1}{m} x = y_2 + \dfrac{1}{m} x_2$.

If you solve these two equations, you will get the coordinates of $D$.

That's straightforward method.

Method 2

Assume that $AD:DC = 1:q$. (If $D$ lies outside $AB$, $q$ will turn out to be negative).

Then $D \equiv (x_4, y_4) = (\frac{x_3 + q x_1}{1 + q}, \frac{y_3 + q y_1}{1 + q})$. Since $BD$ is perpendicular to $AC$, we must have

$\dfrac{y_2 - \dfrac{y_3 + q y_1}{1 + q}}{x_2 - \dfrac{x_3 + q x_1}{1 + q}} % = - \dfrac{x_3 - x_1}{y_3 - y_1} \quad \quad \textit{(= negative reciprocal of slope of $AC$)}$

Solve the equation above for $q$, substitute the value back in $(x_4, y_4)$ and get the co-ordinates. Solving the equation is not as hard as it looks.

$\endgroup$
4
  • $\begingroup$ Using method 2, you will know the ratio in which $D$ divides $AC$ in addition to it's co-ordinates. $\endgroup$
    – jgsmath
    Commented Jun 16, 2017 at 17:51
  • $\begingroup$ So are in the first method in those equations $x = x_4$ and $y = y_4$ ? because I have weird results when I'm calculating the position of D. $\endgroup$
    – jcubic
    Commented Jun 17, 2017 at 9:01
  • $\begingroup$ Method 1 does not work for me and I'm not sure what I've done wrong. The last few steps are not shown and they are critical to understanding how to complete this. Otherwise, I'm wondering if there is a mistake in the answer because I can't get the equations to find a valid D on AC. I picked easy points to use: A = (0,0), C = (5,5), B = (6,2). AC is on y=1*x+0 where m=(5-0)/(5-0)=1. The slope of BD should be -m, so -1. According to the two equations above, it should be y-m*x=0-1*0 and y+(1/m)*x=2+(1/-1)*6. So, y-m*x=0 and y+(1/m)*x=-4. Nothing after this gets a valid point. $\endgroup$
    – Anthony
    Commented Aug 20, 2020 at 19:52
  • $\begingroup$ For anyone else who tries to use Method 2, the general solution for q is shown here where a = y1, b = y2, c = y3, d = x1, e = x2, f = x3. $\endgroup$
    – Anthony
    Commented Aug 20, 2020 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .