This problem feel more complicated to me than usual. I am currently stuck with finding some values in the following case.

enter image description here

Here the image illustrate the basic of the problem. What the rules are :

  • A and B are always on the orange axis
  • AB,DE and CE are of known length
  • ABF, ADB and BEC are 90 degree
  • BF is infinite in that direction

What i need to find is what angle will make BF coincide with C ? By making BF falling down, A move up a bit while B goes toward the left so that make 2 unknowns that for some reason confuse me too much.

You can see the problem as ABF is a partial drawing of a book on angle in a shelf and the orange lines are the side and bottom of the shelf. The book as to touch the side and bottom and i need to know the angle it hold on the vertical toothpick CE

I am a developer so my current solution is to iterate increasing the length of AD and calculating the triangle of ADB and since ABF is also square i have the triangle BEF and F being infinite i get a point perfect inline with CE finally i can check if my F is higher than C if yes bring up A again a bit more and test until F is below C and get somewhere close to the real answer.

There must be a better way to calculate this.

  • $\begingroup$ It is not quite clear what is fixed, what can be changed, and what quantity you are interested in finding. Can you formulate the problem a little more clearly? $\endgroup$ Commented Jan 11, 2023 at 21:42
  • 2
    $\begingroup$ Hint: use similar triangles. $\endgroup$
    – Sai Mehta
    Commented Jan 11, 2023 at 21:44
  • $\begingroup$ The problem, I suppose, confuses you because the confuguration you are looking for is not constructible and uses more variables. By constructible I mean everything could be calculated recursively, or inductively. Here you have defined the solution by lots of equations that hold in the final configuration, and not recursively. Use similar triangles as Sai suggested and translate your constraints as some equations involving solutions of polynomials. You should be able to make it one polynomial. The root of it would be the tanget of the angle you want. $\endgroup$
    – donaastor
    Commented Jan 11, 2023 at 22:17

1 Answer 1


You're correct that there's a better way. However, first note you could more simply, and I believe also easily, explain your goal by stating that with $AB$ being a fixed length, you're trying to determine the position of $B$ on $DE$ so that $AB$ and $BC$ are perpendicular to each other. Thus, this would be equivalent to $C$ and $F$ coinciding. The diagram below shows this, along with a few specified lengths and angles:

Diagram of OP with a few specified lengths and angles added

In particular, as you stated, $|AB| = a$, $|CE| = b$ and $|DE| = c$ are given. Also, set $|DB| = d$ (so $|BE| = c - d$) and $|AD| = e$ as unknown values.

With $\measuredangle ABD = x$ and $\measuredangle BAD = y$, we have $x + y = 90^{\circ}$. Thus, $\measuredangle CBE = 180^{\circ} - 90^{\circ} - x = 90^{\circ} - x = y$, so $\measuredangle BCE = x$. This means $\triangle ADB \sim \triangle BEC$, as indicated in Sai Mehta's comment.

Next, as suggested by donaastor's comment, using the relations among the similar triangles, plus the Pythagorean theorem, results in a system of several equations, which can be reduced to a polynomial in one of the unknown values. First, the Pythagorean theorem with $\triangle ADB$ gives that

$$d^2 + e^2 = a^2 \tag{1}\label{eq1A}$$

Next, using that $\triangle ADB \sim \triangle BEC$, we get

$$\frac{e}{d} = \frac{c-d}{b} \; \; \to \; \; \; e = \left(\frac{c-d}{b}\right)d \tag{2}\label{eq2A}$$

Substituting this into \eqref{eq1A} results in

$$\begin{equation}\begin{aligned} d^2 + \left(\left(\frac{c-d}{b}\right)d\right)^2 & = a^2 \\ (b^2)d^2 + (c-d)^2 d^2 & = a^2(b^2) \\ (b^2)d^2 + (c^2)d^2 - (2c)d^3 + d^4 & = a^2(b^2) \\ d^4 - (2c)d^3 + (b^2 + c^2)d^2 - a^2(b^2) & = 0 \end{aligned}\end{equation}\tag{3}\label{eq3A}$$

Since $a$, $b$ and $c$ are given, this is a quartic equation in the variable $d$. Although \eqref{eq3A} can be solved analytically, as shown in the Wikipedia article, it's usually solved numerically instead, e.g., such as by using the Durand–Kerner method that's also suggested in the article. However, I believe basically all programming languages have either built-in functionality or third-party libraries you can use instead to find the roots (e.g., in Python, there's numpy.roots).

Regardless of how you solve \eqref{eq3A}, with $d$ determined, then $y$ can be calculated in several ways, e.g., by

$$\sin(y) = \frac{d}{a} \; \; \; \to \; \; \; y = \arcsin\left(\frac{d}{a}\right) \tag{4}\label{eq4A}$$

However, especially if you try to solve this with your own code, be careful since quartic equations always have $4$ roots (due to the Fundamental theorem of algebra). I believe there'll usually be $2$ complex conjugates, with the other $2$ being real roots. You want the one with $0 \lt d \lt c$, with the other one being negative, i.e., with $B$ to the left of $D$ (and $A$ below $D$), as shown below:

Diagram showing how it could look with point B to the left of D on BE

From \eqref{eq2A}, we then also have that $e \lt 0$, as the diagram above indicates as well.

I assume you always want $B$ to be between $D$ and $E$. If so, especially if you're using your own root-finding method, you should try to ensure you get the correct root (e.g., by choosing an appropriate starting value) or, at the least, add appropriate checking and handling in case you get an out of bound root (i.e., $d \le 0$ or $d \ge c$) instead.

  • $\begingroup$ I have been at trying to simplify the formula at point #3 for about 4 hours so far but no result yet. I'll still try to go at it for a little while then fall back to the trial and error iterative way as i know i can get a result. Not a good one but a close one and I'll have to do extra 2d collisions to adjust for the errors of the approximate. $\endgroup$
    – Franck
    Commented Jan 12, 2023 at 14:22
  • 1
    $\begingroup$ @Franck Thank you for the feedback, but I'm not clear on a few things. By "point #3", I assume you mean my equation $(3)$. Also, if by "simplify" you mean solving it analytically, I recommend you don't try to do that, as it's fairly complicated and easy to make mistakes. Instead, you should try to solve it numerically, such as using a third-party library (my updated answer suggests numpy.roots if using Python). One last thing to note, as well, is that $\arcsin$ in many computer languages return angles in radians, so you may need to convert to degrees, in case that's the issue. $\endgroup$ Commented Jan 12, 2023 at 19:13
  • 1
    $\begingroup$ Yes i meant the formula at (3). I have finally managed to find a solution for d but it's long as hell and i double checked with Wolfram and it output 4 different solutions. I'll try finding a library in my langage that can solve equations for me to remove the chance of mistake in typing the formula. $\endgroup$
    – Franck
    Commented Jan 12, 2023 at 19:55
  • $\begingroup$ After long hours of work neither mine or WolframAlpha solve for the formula for d = ? at (3) works. I'll have to fall back on iterative to get a close value and integrate the collision detection to adjust to a good enough value $\endgroup$
    – Franck
    Commented Jan 13, 2023 at 16:35
  • $\begingroup$ @Franck I'm sorry you weren't able to get using $(3)$ working properly. However, I don't understand why. I've checked, and rechecked several times, my logic and algebra. After your initial comment, I also manually checked a simple case where $x = y = 45^{\circ}$, with $a = \sqrt{2}$, $b = d = 1$ and $c = 2$. I've just now checked a couple of additional cases. First, I generalized my earlier case with $a = \sqrt{2}d$ and $c = d + b$. Using this in the LHS of $(3)$ gives $d^4 - 2(d+b)d^3 + (b^2 + (d+b)^2)d^2 - 2b^2d^2$. Collecting the terms in the various powers of $d$ together gives for ... $\endgroup$ Commented Jan 13, 2023 at 21:21

You must log in to answer this question.

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