views:

891

answers:

10

Hello everyone,

I have an interesting problem here I've been trying to solve for the last little while:

I have 3 circles on a 2D xy plane, each with the same known radius. I know the coordinates of each of the three centers (they are arbitrary and can be anywhere).

What is the largest triangle that can be drawn such that each vertice of the triangle sits on a separate circle, what are the coordinates of those verticies?

I've been looking at this problem for hours and asked a bunch of people but so far only one person has been able to suggest a plausible solution (though i have no way of proving it).

The solution that we have come up with involves first creating a triangle about the three circle centers. Next we look at each circle individually and calculate the equation of a line that passes through the circle's center and is perpendicular to the opposite edge. We then calculate two intersection points of the circle. This is then done for the next two circles with a result of 6 points. We iterate over the 8 possible 3 point triangles that these 6 points create (the restriction is that each point of the big triangle must be on a separate circle) and find the maximum size.

The results look reasonable (at least when drawn out on paper) and it passes the special case of when the centers of the circles all fall on a straight line (gives a known largest triangle). Unfortunate i have no way of proving this is correct or not.

I'm wondering if anyone has encountered a problem similar to this and if so, how did you solve it?

Note: I understand that this is mostly a math question and not programming, however it is going to be implemented in code and it must be optimized to run very fast and efficient. In fact, I already have the above solution in code and tested to be working, if you would like to take a look, please let me know, i chose not to post it because its all in vector form and pretty much impossible to figure out exactly what is going on (because it's been condensed to be more efficient).

Lastly, yes this is for school work, though it is NOT a homework question/assignment/project. It's part of my graduate thesis (abet a very very small part, but still technically is part of it).

Thanks for your help.

Edit: Heres a new algorithm that i came up with a little while ago.

Starting at a circle's centre, draw a line to the other two centres. Calculate the line that bisects the angle created and calculate the intersections between the circle and the line that passes through the centre of your circle. You will get 2 results. Repeat this for the other two circles to get a total of 6 points. Iterate over these 6 points and get 8 possible solutions. Find the maximum of the 8 solutions.

This algorithm will deal with the collinear case if you draw your lines in one "direction" about the three points.

From the few random trials i have attempted using CAD software to figure out the geometries for me, this method seems to outperform all other methods previously stated However, it has already been proven to not be an optimal solution by one of Victor's counter examples.

I'll code this up tomorrow, for some reason I've lost remote access to my university computer and most things are on it.

A: 

Not optimal, works well when all three are not colinear:

I don't have a proof (and therefore don't know if it's guaranteed to be biggest). Maybe I'll work on one. But:

We have three circles with radius R with positions (from center) P0, P1, and P2. We wish to find the vertices of a triangle such that the area of the triangle is maximum, and the vertices lie on any point of the circles edges.

Find the center of all the circles and call that C. Then C = (P0 + P1 + P2) / 3. Then we find the point on each circle farthest from C.

Find vectors V0, V1, and V2, where Vi = Pi - C. Then find points Q0, Q1, and Q2, where Qi = norm(Vi) * R + Pi. Where norm indicates normalization of a vector, norm(V) = V / |V|.

Q0, Q1, and Q2 are the vertices of the triangle. I assume this is optimal because this is the farthest the vertices could be from each other. (I think.)

GMan
Hmm, that was one of my innital "jump to" answers. However, it did fail the special case in which all three centers are on the same line. Well, either way, let me code it up and see how it preforms given a few random trials (that's how I'm benchmarking each algorithm, throw random meaningless numbers at it until it either breaks, fails, or beats out the other competing algorithms).
Faken
@Faken: How should it perform if the points are colinear? There is no triangle.
GMan
@GMan: Ah, but there is a possible, this is a special case in which there are actual 2 possible solutions. If you align the circles such that their centers are on the x axis, the solution to the maximum would be 1) first circle at maximum y, second at minimum y, third at maximum y, 2) first at minimum y, second at maximum y, third at minimum y. 2 solutions both equal and maximum.
Faken
@Faken: Oh, I see what you mean. Interesting. I'll leave me answer up for now, I'll see if I can come up with a better answer.
GMan
I coded up the second algoritum and ran it against the first one, the first one still comes out on top all the time in a 10 million random numbers trial.
Faken
A: 

My first thought is that you should be able to find an analytic solution.

Then the equations of the circles are:

(x1-h1)^2 + (y1-k1)^2 = r^2
(x2-h2)^2 + (y2-k2)^2 = r^2
(x3-h3)^2 + (y3-k3)^2 = r^2

The vertices of your triangle are (x1, y1), (x2, y2), and (x3, y3). The side lengths of your triangle are

A = sqrt((x1-x2)^2 + (y1-y2)^2)
B = sqrt((x1-x3)^2 + (y1-y3)^2)
C = sqrt((x2-x3)^2 + (y2-y3)^2)

So the area of the triangle is (using Heron's formula)

S = (A+B+C)/2
area = sqrt(S(S-A)(S-B)(S-C))

So area is a function of 6 variables.

At this point I realize this is not a fruitful line of reasoning. This is more like something I'd drop into a simulated annealing system.

So my second thought is to choose the point on circle with centre A as follows: Construct line BC joining the centres of the other two circles, then construct the line AD that is perpendicular to BC and passes through A. One vertex of the triangle is the intersection of AD and circle with centre A. Likewise for the other vertices. I can't prove this but I think it gives different results than the simple "furthest from the centre of all the circles" method, and for some reason it feels better to me. I know, not very mathematical, but then I'm a programmer.

David
Okay, I'm an idiot. I reread your post (after skimming the first time) and realized that my second thought is actually the solution you already have. Maybe take that as a good sign that I came up with it independently?
David
Yea, my very first reaction to the problem was also to find the analytical solution (because it can be proven). I fired up Matlab and kind of did what you suggested there except i used the determinate method to solve the surface area. Then i attempted to take a derivative of it, set it to zero and solve the the maximum/minimums of a systems of 6 equations. Needless to say, Matlab now hates me...
Faken
Yup, it is a good sign!
Faken
You can get it down to 3 variables if you write each point on the circle as a function of an angle (since the radius is fixed). I'm not sure if that's any more useful though. And remember that maximizing area squared is equivalent to maximizing area (and usually easier). I suspect that if you write it down like this, you'll get the partial derivative w.r.t. each angle to have two zeroes corresponding to a local minimum and local maximum, and then you can simultaneously solve for all three maxima, but that's just my gut.
celion
@celion: Good point, I'll give it another try with Matlab.
Faken
A: 

Let's assume the center of the circles to be C0,C1 and C2; and the radius R.

Since the area of a triangle is .5*base*height, let's first find the maximum base that can be constructed with the circles. Base = Max {(|C0-C1|+2R),(|C1-C2|+2R,(|C2-C0|+2R}

Once the base length is determined between 2 circles, then we can find the farthest perpendicular point from the base line to the third circle. (product of the their slopes is -1)

For special cases such as circles aligned in a single line, we need to perform additional checks at the time of determining the base line.

AV
Hmm, interesting, i hadn't thought of this one yet. Though I think there will be a problem if we look at a special case of when the points form an equilateral triangle. Its difficult to explain, but the triangle generated by this algorithm would be smaller than one generated by a "maximum distance from center" algorithm which would be equal to the "perpendicular center intersection" algorithm.
Faken
A: 

It appears that finding the largest Apollonius circle for the three circles and then inscribing an equilateral triangle in that circle would be a solution. Proof left as an exercise ;).

EDIT

This method has issues for collinear circles like other solutions here, too and doesn't work.

honk
Oh! Now there's something interesting, give me a few mins too look it over. Actually this is exactly the kind of answer i was hoping for.
Faken
Consider three collinear circles, the Apollonius circle of this configuration that contains all three circles would be infinite in radius (it is a halfspace). The inscribed triangle degenerates to a line segment, and is not the best you can do. Am I misunderstanding what you said?
Victor Liu
Hm, this seems to have problems for close to collinear circles, too.
honk
@Victor: no, we agree
honk
Sorry guys, i kinda run and catch a bus before they all stopped coming. Another point i am missing is that I'm not so much as after the surface area, rather I'm looking for the coordinates of the three verticies.
Faken
+2  A: 

I believe this is a convex optimization problem (no it's not, see below), and hence can be solved efficiently using well known methods.

You essentially want to solve the problem:

maximize:  area(v1,v2,v3) ~ |cross((v2-v1), (v3-v1))|
such that: v1 in C1, v2 in C2, v3 in C3   (i.e., v_i-c_i)^2 - r_i^2 <= 0)

Each of the constraints are convex, and the area function is convex as well. Now, I don't know if there is a more efficient formulation, but you can at least use an interior point method with derivatives since the derivative of the area with respect to each vertex position can be worked out analytically (I have it written down somewhere...).

Edit: grad(area(v1,v2,v3))(v_i) = rot90(vec(vj,vk)), where vec(a,b) is making a 2D vector starting at a and ending at b, and rot90 means a positive orientation rotation by 90 degrees, assuming (vi,vj,vk) was positively oriented.

Edit 2: The problem is not convex, as should be obvious considering the collinear case; two degenerate solutions is a sure sign of non-convexity. However, the configuration starting at the circle centers should be in the globally optimal local maximum.

Victor Liu
You can actually get it down to 3 variables for arbitrary radii by rotating and shifting one side to be on an axis, and for same radii it reduces to a single variable ODE.
honk
In what sense do you call area a convex function (i.e. what area the arguments)?
AVB
I'll give it a try and see what happens. Though unfortunately I'm quite busy tomorrow and might not be able to work on it much then, but I'll check back here when i get time, I'll try to solve it analytically using honk's idea of reducing variables and rotating it.
Faken
Well, I already have an algorithm in place that stands up to the the case of collinear centres and gives a correct (or rather, assumed to be correct) answer, in fact it gives BOTH of the correct answers (although since I'm at home and my remote access to the university computer suddenly stopped working, i cant test the other cases in which there are coincident points, frustrating!). Maybe we can work backwards and prove the method rather than trying to solve it? I just don't have a strong enough math background to prove it.
Faken
The solution for the collinear case is derivable so you can check to see if your answer is correct. Assuming one circle at the origin, the others at x=1,-1, radius r, the middle vertex must be at (0,r), and the y coordinate of the other two vertices is given by `f[rr_] := y /. Solve[-1 - ((r - y) y)/Sqrt[r^2 - y^2] - Sqrt[r^2 - y^2] == 0 /. {r -> rr}, y] // First` (Mathematica expression)
Victor Liu
The method you originally proposed might be the fastest Faken if it is correct, but this can be pretty easily solved using a least squares method. I agree with the conditions given in Victor's code block except that I would change the <= to a =. The point will be on the edge of the circle. Also, I would minimize the negative of the square of the area. The area of the triangle is actually what he gave divided by two, but that doesn't matter for a max/minimization problem like this. I got Mathematica to solve it very quickly as a least squares problem and you can use that to check your answers.
Justin Peel
@Justin: I wrote it that way since it tends to be harder to enforce an equality constraint; an optimal solution must necessarily lie on the manifold defined by equality so it's a non-issue. I believe the solution posted above in Faken's question is not correct for triangles far from equilateral.
Victor Liu
A: 

Some initial thoughts.

  1. Definition Call the sought-after triangle, the maximal triangle. Note that this might not be unique: if the circles all have the same centre, then there are infinitely many maximal triangles obtained by rotation around the center, and if the centres are colinear, then there will be two maximal triangles, each a mirror image of the other.
  2. Definition Call the triangle (possibly, degenerately, either a point or a line) whose vertices are the centres of the circles the interior triangle.
  3. Observation The solution can be expressed as three angles, indicating where on the circumference of each circle the triangle is to be found.
  4. Observation Given two exterior vertices, we can determine a third vertex that gives the maximal area: draw the altitude of the triangle between the two exterior vertices and the centre of the other circle. This line intersects the circumference in two places; the further away point is the maximising choice of third vertex. (Fixed incorrect algorithm, Federico's argument can be adapted to show correctness of this observation)
  5. Consequence The problem is reduced to from a problem in three angles to one in two.
  6. Conjecture Imagine the diagram is a pinboard, with three pins at the three centres of the circles. Imagine also a closed loop of string of length equal to the perimiter of the interior triangle, plus the radius of a circle, and we place this loop around the pins. Take an imaginary pen and imaginarily draw the looping figure where the loop is always tight. I conjecture that the points of the maximal triangle will all lie on this looping figure, and that in the case where the interior triangle is not degenerate, the vertices of the maximal triangle will be the three points where the looping figure intersects one of the circle circumferences. Many counterexamples

More to follow when I can spare time to think about it.

Charles Stewart
If you only add a length to the string equal to the radius, this fails in the equilateral case, as the string cannot intersect the circle at the point farthest from the other two circles.
Victor Liu
@Victor: post updated.
Charles Stewart
+3  A: 

Let A, B, C be the vertexes of your triangle, and suppose they are placed as in your solution. Notice that the key property of your construction is that each of the vertexes lies on a tangent to its circle which is parallel to the opposite side of the triangle. Obviously, the circle itself lies entirely on one side of the tangent, and in the optimal solution each tangent leaves its circle on the same side as the other vertexes.

Consider AB as the "base" of the triangle, and let C float in its circle. If you move C to another position C' within the circle, you will obtain another triangle ABC' with the same base but a smaller height, hence also with a smaller area:

figure 1

For the same reason, you can easily see that any position of the vertexes that doesn't follow your construction cannot be optimal. Suppose, for instance, that each one of the vertexes A', B', C' does not lie on a tangent parallel to the side connecting the other two.

Then, constructing the tangent to the circle that contains (say) C', which is parallel to A'B' and leaves the circle on the same side as A'B', and moving C' to the point of tangency C, it is always possible to construct a triangle A'B'C which has the same base, but a greater height, hence also a greater area:

figure 2

Since any triangle that does not follow your construction cannot be optimal, I do believe that your construction is optimal. In the case when the centers of the circles are aligned I'm a bit confused, but I guess that it is possible to prove optimality along the same lines.

Federico Ramponi
This is pretty much the original algorithm that my friend came up with, as posted in the question. The algorithm would produce a total of 8 possible triangle configurations (3 circles, 2 tangents per circle, total combination of 8 triangles). As for the collinear case, the algorithm dose provide plausible solutions. Though, Victor has already provided a counter example of other triangles.
Faken
The algorithm is nearly optimal in the limit of vanishing radius, but not optimal. You can imagine an iteration in which the triangle is expanded in the way described above, and then contracted slightly and re-expanded. Something like this would likely converge to the optimal solution.
Victor Liu
The collinear case is essentially the same problem, the difference being that there exist multiple solutions. Besides this case, you don't need to go through all the 8 triangles: just be sure to choose the correct tangent for each circle - the one that leaves the circle on the same half-plane of the other two [circles] centers. In this way you have to perform just 3 comparisons, and you can avoid computing the 8 areas.
Federico Ramponi
@Victor: my intent was not to provide an iterative algorithm converging to the optimal solution (although I guess it could be done along the same lines, iterating through the vertexes). It was to prove that Faken's solution is actually optimal. If a triangle does not follow Faken's construction it is not optimal, therefore Faken's construction is optimal. I think that with his method we can _construct_ the optimal solution analytically, there is no need for optimization algorithms here. (Notice: I still have reserves about the above sketch of proof in the collinear case).
Federico Ramponi
Thank you for adding schemas, that does make geometry easier! I am not sure however that your demonstration is correct: it relies on only moving one point at a time. For example, considering the first schema, what would happen if we decided to move both A and B (either down or up) at once so that (A', B') is parallel to (A,B) and A' and B' still remain on the circle ? If H is the projection of C on (A,B) and H' on (A',B'), are you sure that CH x AB > CH' x A'B' ? I find it hard to quantify since both terms vary.
Matthieu M.
Using `@brainjam` simulator, you'll see that it's not working. Get close to a colinear case and you'll notice it.
Matthieu M.
How are you making these cool diagrams?
RBarryYoung
+7  A: 

I've created an HTML5 canvas app that may be useful for people to play with. It's pretty basic (and the code is not beautiful), but it lets you move three circles of equal radius, and then calculates a maximal triangle using gradient/steepest descent. You can also save bitmaps of the diagram. The diagram also shows the triangle whose vertices are the circle centers, and one of the altitudes. Edit1: the "altitude" is really just a line segment through one of the circle centers and perpendicular to the opposite edge of the triangle joining the centers. It's there because some of the suggested constructions use it. Edit2: the steepest descent method sometimes gets stuck in a local maximum. You can get out of that maximum by moving a circle until the black triangle flips and then bringing the circle back to its original position. Working on how to find the global maximum.

This won't work in IE because it doesn't support canvas, but most other "modern" browsers should work.

I did this partially because I found some of the arguments on this page questionable, and partially because I've never programmed a steepest descent and wanted to see how that worked. Anyways, I hope this helps, and I hope to weigh in with some more comments later.

Edit: I've looked at the geometry a little more and have written up my findings in a separate answer.

brainjam
Bug: I've observed a situation where the wrong altitude is calculated for the interior triangle. I'll send on the bitmap.
Charles Stewart
Oh great, now that's going to help!
Matthieu M.
@Charles Stewart, thanks for the bitmap. I think it's correct, the green line is is perpendicular to the opposite blue edge (even though it doesn't intersect it). (sorry, nobody on SO can see the bitmap in question)
brainjam
A: 
andand
+5  A: 

I've taken the liberty of submitting a second answer, because my original answer referred to an online app that people could play with to get insight. The answer here is more a geometric argument.

The following diagram illuminates, I hope, what is going on. Much of this was inspired by @Federico Ramponi's observation that the largest triangle is characterized by the tangent at each vertex being parallel to the opposite side.

alt text

The picture was produced using a trial version of the excellent desktop program Geometry Expressions. The diagram shows the three circles centered at points A,E, and C. They have equal radii, but the picture doesn't really depend on the radii being equal, so the solution generalizes to circles of different radii. The lines MN, NO, and OM are tangent to the circles, and touch the circles at the points I,H, and G respectively. The latter points form the inner triangle IHG which is the triangle whose size we want to maximize.

There is also an exterior triangle MNO which is homethetic to the interior triangle, meaning that its sides are parallel to that of IHG.

@Federico observed that IHG has maximal area because moving any of its vertices along the corresponding circle will result an a triangle that has the same base but less height, therefore less area. To put it in slightly more technical terms, if the triangle is parameterized by angles t1,t2,t3 on the three circles (as pointed out by @Charles Stewart, and as used in my steepest descent canvas app), then the gradient of the area w.r.t to (t1,t2,t3) is (0,0,0), and the area is extremal (maximal in the diagram).

So how is this diagram computed? I'll admit in advance that I don't quite have the full story, but here's a start. Given the three circles, select a point M. Draw tangents to the circles centered at E and C, and designate the tangent points as G and I. Draw a tangent OHN to the circle centered at A that is parallel to GI. These are fairly straightforward operations both algebraically and geometrically.

But we aren't finished. So far we only have the condition that OHN is parallel to GI. We have no guarantee that MGO is parallel to IH or that MIN is parallel to GH. So we have to go back and refine M. In an interactive geometry program it's no big deal to set this up and then move M until the latter parallel conditions are met (by eyeballs, anyways). Geometry Expressions created the diagram, but I used a bit of a cheat to get it to do so, because its constraint solver was apparently not powerful enough to do the job. The algebraic expressions for G, I, and H are reasonably straightforward, so it should be possible to solve for M based on the fact that MIHG is a parallelogram, either explicitly or numerically.

I should point out that in general if you follow the construction starting from M, you have two choices of tangent for each circle, and therefore eight possible solutions. As in the other attempted answers to the question, unless you have a good heuristic to help you choose in advance which of the tangents to compute, you should probably compute all eight possible triangles and find the one with maximum area. The other seven will be extremal in the sense of being minimal area or saddle points.

That's it. This answer is not quite complete in that it leaves the final computation of M somewhat open ended. But it's reduced to either a 2D search space or the solution of an ornery but not humongous equation.

Finally, I have to disagree with @Federico's conclusion that this confirms that the solution proposed by the OP is optimal. It's true that if you draw perpendiculars from the circle centers to the opposite edge of the inner triangle, those perpendiculars intersect the circle to give you the triangle vertex. E.g. H lies on the line through A perpendicular to GI), but this is not the same as in the original proposed solution (which was to take the line through A and perpendicular to EC - in general EC is not parallel to GI).

brainjam
Brainjam, I thank you for your work on this question, I think you have spent more time on this problem than even myself! To be honest, i didn't expect to attract such talented crowd, you guys are truly a cut above. Originally i had posted this question in hopes that this problem had already been solved and someone only needed to point me towards a solution, but it seems that this is not as simple as i had once thought. I think I'm going to award you the best answer and move on with my project despite not having an absolute best answer, but your free to explore this problem at your leisure.
Faken
So it seems that we only have properties of the final result and there is no other method other than to do some iterations to find the answer. Well, this is by far one of the best answers as it seems to really have some insight into whats really going on. Unfortunately, as you all know, requirements of programming projects change all the time and I've realized that this approach to my particular application is, in the end, not what was truly needed for the problem. Instead, i need to tackle the problem from another angle that I have yet to discover. Thanks for your help on this problem.
Faken
@Faken, according to the stats, you have posted the 4th most popular geometry question to date, if you measure by upvotes. Obviously many people found this an interesting question, and some of us have spend way too much time on it (but learned a few things along the way). Certainly a welcome break from the "why doesn't my <div> look right" questions. Good luck on your project and problem.
brainjam