That's a two coffee problem. I changed notation to get rid of the subscripts while I solved it, and I'll use my notation here to make my life easier: let the co-ordinates of A be (A, a), of B be (B, b), and of C be (C, c). We want to find a point (D, d) which:
- lies on the perpendicular to AC which passes through B
- gives us a predetermined angle Blimit at ADC
If you just steam ahead and try to solve for D and d, you'll end up in an algebraic mess - you'll find you have a fraction with about thirty terms in it. Co-ordinate geometry becomes a lot easier if you're dealing with horizontal and vertical lines. To solve the general problem, it will be easiest to do the following:
- Translate all our points (by subtracting A from each x co-ordinate and a from each y co-ordinate) so that point A is at (0,0)
- Rotate all our points about (0,0) = A, so that point C lies on the x axis. That is, we have translated point C so it is now at (C - A, c - a). If the slope of AC is positive, then the line AC will form an angle of arctan( (c-a) / (C-A) ) with the x -axis; we want to rotate all our points by that angle. I'll assume you have a rotation function implemented.
- We then solve the problem in the translated and rotated situation.
- Finally, we just need to reverse our rotation and translation to get our solution back to the original situation.
So, we can assume that (A, a) = (0,0), that (C, c) = (C, 0), and that D = B, so (D, d) = (B, d).
We need to find d so that (D, d) gives us the correct angle. At the point where two lines with slopes m and n meet, the smaller (acute, so < 90 degree) angle formed at their intersection point is given by:
tan(Theta) = | (m - n)/(1 + mn) |
Now, I'm guessing, given your setup, that the angle you've called Blimit will be greater than 90 degrees. If that's the case, then the Theta in the formula above is not equal to Blimit; instead, Theta is going to be equal to 180 - Blimit.
The slopes m and n that we are concerned with here are:
m = slope of DA = d/D = d/B
n = slope of DC = d/(B - C)
so we have:
tan(Theta) = | ( (d/B) - (d/(B - C)) )/(1 + (d/B)(d/(B - C)) ) |
tan(Theta) = | [( -dC)/(B(B-C))] / [( B(B-C) + d^2)/(B(B-C)) ] |
and thankfully we get some cancellation:
tan(Theta) = | (dC)/(B^2 - CB + d^2) |
By our assumption above that Blimit is greater than 90 degrees, 1 + mn will be positive, so we should have:
tan(Theta) = dC/(B^2 - CB + d^2)
If Blimit is less than 90, you'd want to introduce a negative sign on the right side of the equation. Now, tan(Theta) is a known value; I'll call it T for simplicity:
T(B^2 - CB + d^2) = dC
(T)d^2 - (C)d + TB^2 - TBC = 0
Every number here is known besides d; we can use the quadratic formula to find d:
d = (C +/- sqrt(C^2 - 4T(TB^2 - TBC)) )/2T
You'll presumably want to choose the positive solution if the slope of AB is positive:
d = (C + sqrt(C^2 - 4BT^2(B - C)) )/2T
Notice that this is certain to have a solution if 0 < B < C; under the root we have C^2 - 4B (tan^2 (theta))(B-C); C^2 is positive, and B-C is negative, so 4B (tan^2 (theta))(B-C) must be negative; since we are subtracting a negative from a positive, we are certain to have a positive value under the root. Just remember that T = tan(Theta) = tan(180 - Blimit); the angle Theta is not the same as Blimit, if Blimit > 90 degrees.
Now that we have d, we just need to rotate, then translate, (D, d) back into the position of the original diagram, and we're done.
There's quite a few steps in the above, but I just checked that it works for one set of numbers, so I'm pretty sure everything is correct.