tangent of two circles

Posted by harryovers on Stack Overflow See other posts from Stack Overflow or by harryovers
Published on 2010-03-16T20:50:15Z Indexed on 2010/03/16 20:51 UTC
Read the original article Hit count: 350

Filed under:
|
|
|
|

Hello,
I am trying to write some code that that will draw the line which is a tangent between 2 circles. so far i have been able to draw multiple circles, and lines between the centers.
i have a class which stores the values used in drawing the circles (radius, position). what i need is a method in this class to find all posible tangents between 2 circles.
any help would be great.
this is what i have so far (it could very well be a load of rubbish)

public static Vector2[] Tangents(circle c1, circle c2)
{
            if (c2.radius > c1.radius)
            {
                circle temp = c1;
                c1 = c2;
                c2 = temp;
            }
            circle c0 = new circle(c1.radius - c2.radius, c1.center);
            Vector2[] tans = new Vector2[2];
            Vector2 dir = _point - _center;
            float len = (float)Math.Sqrt((dir.X * dir.X) + (dir.Y * dir.Y));
            float angle = (float)Math.Atan2(dir.X, dir.Y);
            float tan_length = (float)Math.Sqrt((len * len) - (_radius * _radius));
            float tan_angle = (float)Math.Asin(_radius / len);
            tans[0] = new Vector2((float)Math.Cos(angle + tan_angle), (float)Math.Sin(angle + tan_angle));
            tans[1] = new Vector2((float)Math.Cos(angle - tan_angle), (float)Math.Sin(angle - tan_angle));
            Vector2 dir0 = c0.center - tans[0];
            Vector2 dir1 = c0.center - tans[1];

            Vector2 tan00 = Vector2.Add(Vector2.Multiply(tans[0], (float)c2.radius), c1.center);
            Vector2 tan01 = c2.center;
            Vector2 tan10 = Vector2.Add(Vector2.Multiply(tans[1], (float)c2.radius), c1.center);
            Vector2 tan11 = c2.center;
}

© Stack Overflow or respective owner

Related posts about XNA

Related posts about circle