예제 #1
0
        public static bool IsCircleInsectCircle2(Vector2 center1, float r1, Vector2 center2, float r2, ref GeoInsectPointArrayInfo insect)
        {
            // MatrixUtils
            Vector2 cc1  = center2 - center1;
            float   cc1d = cc1.magnitude;

            if (cc1d > (r1 + r2))
            {
                return(false);
            }
            if (r1 > r2 && IsInCircle(center1, r1, center2)) // 内部
            {
                if (r1 > (r2 + cc1d))
                {
                    return(false);
                }
            }
            if (r1 < r2 && IsInCircle(center2, r2, center1))
            {
                if (r2 > (r1 + cc1d))
                {
                    return(false);
                }
            }
            Vector2 cc = center1 + cc1 * 0.5f;

            if (cc1d == (r1 + r2))
            {
                insect.mIsIntersect = true;
                insect.mHitGlobalPoint.mPointArray.Add(new Vector3(cc.x, cc.y, 0.0f));
                return(true);
            }
            float dist = cc1.sqrMagnitude * 0.25f;

            cc1.Normalize();
            Vector2 v1, v2;

            MatrixUtils.CreateMatrix2D(90, out v1, out v2);
            float   x     = Vector2.Dot(v1, cc1);
            float   y     = Vector2.Dot(v2, cc1);
            Vector2 vertD = new Vector2(x, y);

            vertD.Normalize();
            float   len = Mathf.Sqrt(r1 * r1 - dist);
            Vector2 p1  = cc + len * vertD;
            Vector2 p2  = cc - len * vertD;

            insect.mIsIntersect = true;
            insect.mHitGlobalPoint.mPointArray.Add(new Vector3(p1.x, p1.y, 0.0f));
            insect.mHitGlobalPoint.mPointArray.Add(new Vector3(p2.x, p2.y, 0.0f));
            return(false);
        }
예제 #2
0
        public static List <Vector2> CalculateCircle(float angle, float r, Vector2 center)
        {
            List <Vector2> cir  = new List <Vector2>();
            Matrix2x2      mat2 = MatrixUtils.CreateMatrix2D(angle, center);

            mat2.Scale = Vector2.one * r;
            Vector2 start = new Vector2(0, 1);
            int     count = (int)(360.0f / angle);

            for (int i = 0; i < count; ++i)
            {
                Vector2 next = mat2.Rotate(start);
                start = next.normalized;
                cir.Add(start * r + center);
            }
            return(cir);
        }