This problem stems from a British Standard for staircases, of all things (BS 5395-1 2010, diagram B4 p.27), which prescribes the position of stairs when they turn a corner. I've tried to find an easy way to calculate the positions rather than use "pen and paper", but because it's based on ellipses, I can't find a way to create a good calculation method for it. I've abstracted the "real world" problem and would like ideas how best to approach it.
Definitions:
- P1, P2 and P3 are three arbitrary points not in a straight line; (x1,y1) are the co-ordinates of P1; L1 and L2 are the line segments P1-P3 and P2-P3.
- e is an ellipse drawn tangent to L1 at P1 and tangent to L2 at P2.
- k is an arbitrary parameter required to fix one specific ellipse e out of the many ellipses that could be drawn - needed because the original problem only specifies 4 constraints for an ellipse, and an ellipse needs 5.
- G is a number > 0 that is "small-ish" compared to the distance between P1 and P2 (in the real world problem G would be about 20% to 50% of the distance between P1 and P2). This condition ensures that the intersection (x2,y2) described below actually exists, and that the problem isn't pathological or degenerate.
The problem is to determine formulaically - ie not using approximations - the points (x1,y1) (x2,y2) etc constructed by this algorithm:
Draw the points P1, P2, P3 and the line segments L1, L2.
Draw an ellipse e that is tangent to L1 at P1 and tangent to L2 at P2. Because there may be an infinity of such ellipses (4 constraints, 5 required), this step requires us to create some convenient way to parameterise the problem with a 5th parameter "k" which can be varied to choose one unique ellipse out of all possible tangential ellipses for a given {P1, P2, P3}.
Draw a circle radius G centre P1. Because of the "small-ish" limit on G, this circle will intersect the ellipse e at some point of its arc between P1 and P2. Call this point (x2,y2).
Continue repeating step 3, at each iteration drawing a circle radius G centre (x(n),y(n)) and call the next intersection with the ellipse e, (x(n+1),y(n+1)), then a circle centre (x(n+1), y(n+1)) with intersection (x(n+2),y(n+2)), etc. Stop when we would go past P2. In the "real world" problem we will have constructed no more than 4, perhaps 5 points (x2,y2) through (x4 or x5, y4 or y5).
The "stop at P2" constraint means our solution doesn't need to consider any intersections on the "return arc" of the ellipse; and the smallness of G means that our circle at (say) (x3,y3) must always intersect the ellipse e at just two points: (x2,y2) which we already know, and (x4,y4) which is the point we want - it can't touch the "far side" of the ellipse or fail to touch it at all.
The problem is to pick a convenient parameterisation method ("k") and then, given arbitrary P1, p2, P3, G, k, determine the co-ordinates of all (xn,yn). I'd like to avoid "brute force" methods such as approximation techniques but I can't see how. Is there a "sensible" way to do this algebraically? How might I go about it?
Update 1:
I solved the first part (I think) by using a property of tangents to an ellipse, namely that lines from either focus of an ellipse to a point on its perimeter, will make a constant angle with the tangent at that point. Switching that around, if I choose 0 <= α < 90 as an arbitrary angle, then a line at α to the tangent must pass through a focus of the ellipse, from both P1 and P2. I can therefore find my unique ellipse, which is the first part of the problem, this way:
Construct the normals N1 and N2, passing through P1 and P2 (easy, as I have the direction of the tangents at both points).
Pick an arbitrary angle 0 <= α < 90. This will be my parameter "k" above, the 5th parameter needed to identify a unique ellipse among all possible solutions.
Rotate both normals around their respective points by (α). That is, rotate N1 using centre P1 and rotation = α, and rotate N2 using centre P2 and rotation = α. Identify the point these intersect as F1.
Do the same again, but this time rotating both normal by (-α). Again the normals will intersect and call this point F2.
The unique ellipse for (P1, P2, L1, L2, α) is an ellipse with foci (F1) and (F2). Its eccentricity can be found by usual ellipse properties as we know both foci and a point on the perimeter (ie the distance F1-P1-F2 etc). Its axes can be found by constructing the line F1-F2 and its bisector, and so on.
Note, I used the normal not the tangent because then the foci are at +/- α, not α and (180-α), which is simpler :)
Also, the family of solutions can be found by varying α, and I think that this must generate all solutions since any ellipse that is a solution must by definition have lines from its foci to P1 and P2 that are at some identical angle (α) to L1 and L2.
Now just to solve the intersection of the circles and the ellipses.
So far, is this correct? Is this necessary, or n & sufficient?
diagram of this update, showing constructions
(this bit struck out as incorrect, see comment below)