### Finding a tangent circle

#### Nexys

• Posts: 14
Okay, so here's the situation:

I have three actors that may be placed in any possible relation to each other, but they don't move. Thus, they are basically the three points of a static triangle. For each of these points, I need to find a circle that is tangent to the shortest adjacent side of the triangle at its midpoint, and also tangent to the other adjacent side (but not necessarily at the midpoint). Basically, I need a curve that fits nicely into each corner of the triangle.

I've been going back to my trig textbooks to try to pull this together, but so far the only leads on a solution that I've found seem like they'd be pretty computationally expensive (I may need to do this calculation a few times for each level of the game). What's the most efficient way to calculate the center point and radius of these circles?

#### herby

• Posts: 124
I've been going back to my trig textbooks to try to pull this together, but so far the only leads on a solution that I've found seem like they'd be pretty computationally expensive (I may need to do this calculation a few times for each level of the game).

A few trigonometric calculations is not computationally expensive... and it surely could be computed by just a few operations.

The point you are looking for is in the intersection of the axis of the "shortest adjacent side", as it is the set of all points that can act as centre of circle that touches the "shortest adjacent side" centre; and the parabola, as it is the set of all points equally distant from a point ("shortest adjacent side" centre) and a line ("other adjacent side").
So in fact, you only have two equations, one for the axis, one for the parabola, and you just solve it to find the intersection. The equations of the line and of the parabola are in any math book on this topic or on the net, they are linear (the line) or quadratic (the parabola) on x and y. It should be pretty simple - deriving one variable from the other based on line equation and substituting it back to the parabola equation and you end up with a plain quadratic equation for one variable.

#### herby

• Posts: 124
Sorry, there is a simpler solution - you only need the intersection of two lines - the axis of the "shortest adjacent side" and the axis of the angle itself.
Mea culpa, the solution I proposed was too complicated.
Finding the intersection of two lines is not computationally expensive, it's just some simple formula or two.

#### Nexys

• Posts: 14
Thanks, Herby.

To be honest, I was sort of hoping there would be some nice pre-packaged equations I could use, but I've started putting together something that I think will work based on the intersection of lines like you mentioned.  I'll post again here if I run into trouble (or if I succeed, I guess).

#### herby

• Posts: 124
Well, lines can be represented either by
ax+by+c = 0
which is general equation for lines, but for this situation I think the best is to use start + direction approach
(x,y) = (xstart, ystart) + t.(xdir, ydir)
since you know pretty well the start points as well as directions for those lines (to get the direction for the angle axis, just normalize both directions for the sides and add them).
Finding the common point would be just solving "first right part = second right part" with added value that you already have the radius (t of the axis of the shortest adjacent side (if its direction was normalized)).