CircleTangents.FindCircleCircleTangents(UnityEngine.Vector2, float, UnityEngine.Vector2, float, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2)

Here are the examples of the csharp api CircleTangents.FindCircleCircleTangents(UnityEngine.Vector2, float, UnityEngine.Vector2, float, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2, out UnityEngine.Vector2) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : CircleTangents.cs
License : MIT License
Project Creator : BelkinAndrey

public static int FindCircleCircleTangents(
            Vector2 c1, float radius1, Vector2 c2, float radius2,
            out Vector2 outer1_p1, out Vector2 outer1_p2,
            out Vector2 outer2_p1, out Vector2 outer2_p2,
            out Vector2 inner1_p1, out Vector2 inner1_p2,
            out Vector2 inner2_p1, out Vector2 inner2_p2)
        {
            // Make sure radius1 <= radius2.
            if (radius1 > radius2)
            {
                // Call this method switching the circles.
                return FindCircleCircleTangents(
                    c2, radius2, c1, radius1,
                    out outer2_p2, out outer2_p1,
                    out outer1_p2, out outer1_p1,
                    out inner1_p2, out inner1_p1,
                    out inner2_p2, out inner2_p1);
            }

            // Initialize the return values in case
            // some tangents are missing.
            outer1_p1 = new Vector2(-1, -1);
            outer1_p2 = new Vector2(-1, -1);
            outer2_p1 = new Vector2(-1, -1);
            outer2_p2 = new Vector2(-1, -1);
            inner1_p1 = new Vector2(-1, -1);
            inner1_p2 = new Vector2(-1, -1);
            inner2_p1 = new Vector2(-1, -1);
            inner2_p2 = new Vector2(-1, -1);

            // ***************************
            // * Find the outer tangents *
            // ***************************
            {
                float radius2a = radius2 - radius1;
                if (!FindTangents(c2, radius2a, c1, out outer1_p2, out outer2_p2))
                {
                    // There are no tangents.
                    return 0;
                }

                // Get the vector perpendicular to the
                // first tangent with length radius1.
                float v1x = -(outer1_p2.y - c1.y);
                float v1y = outer1_p2.x - c1.x;
                float v1_length = (float)Mathf.Sqrt(v1x * v1x + v1y * v1y);
                v1x *= radius1 / v1_length;
                v1y *= radius1 / v1_length;
                // Offset the tangent vector's points.
                outer1_p1 = new Vector2(c1.x + v1x, c1.y + v1y);
                outer1_p2 = new Vector2(outer1_p2.x + v1x, outer1_p2.y + v1y);

                // Get the vector perpendicular to the
                // second tangent with length radius1.
                float v2x = outer2_p2.y - c1.y;
                float v2y = -(outer2_p2.x - c1.x);
                float v2_length = (float)Mathf.Sqrt(v2x * v2x + v2y * v2y);
                v2x *= radius1 / v2_length;
                v2y *= radius1 / v2_length;
                // Offset the tangent vector's points.
                outer2_p1 = new Vector2(c1.x + v2x, c1.y + v2y);
                outer2_p2 = new Vector2(outer2_p2.x + v2x, outer2_p2.y + v2y);
            }

            // If the circles intersect, then there are no inner tangents.
            float dx = c2.x - c1.x;
            float dy = c2.y - c1.y;
            float dist = Mathf.Sqrt(dx * dx + dy * dy);
            if (dist <= radius1 + radius2) return 2;

            // ***************************
            // * Find the inner tangents *
            // ***************************
            {
                float radius1a = radius1 + radius2;
                FindTangents(c1, radius1a, c2, out inner1_p2, out inner2_p2);

                // Get the vector perpendicular to the
                // first tangent with length radius2.
                float v1x = inner1_p2.y - c2.y;
                float v1y = -(inner1_p2.x - c2.x);
                float v1_length = (float)Mathf.Sqrt(v1x * v1x + v1y * v1y);
                v1x *= radius2 / v1_length;
                v1y *= radius2 / v1_length;
                // Offset the tangent vector's points.
                inner1_p1 = new Vector2(c2.x + v1x, c2.y + v1y);
                inner1_p2 = new Vector2(inner1_p2.x + v1x, inner1_p2.y + v1y);

                // Get the vector perpendicular to the
                // second tangent with length radius2.
                float v2x = -(inner2_p2.y - c2.y);
                float v2y = inner2_p2.x - c2.x;
                float v2_length = (float)Mathf.Sqrt(v2x * v2x + v2y * v2y);
                v2x *= radius2 / v2_length;
                v2y *= radius2 / v2_length;
                // Offset the tangent vector's points.
                inner2_p1 = new Vector2(c2.x + v2x, c2.y + v2y);
                inner2_p2 = new Vector2(inner2_p2.x + v2x, inner2_p2.y + v2y);
            }

            return 4;
        }