예제 #1
0
        private static bool intersectsLinears(LinearPath a, float widthA, LinearPath b, float widthB, IntersectionMode mode, out float offsetA, out float offsetB)
        {
            var aP = t2d(a.Start);
            var aD = t2d(a.Dir);
            var aT = t2d(a.Tangent);

            var bP = t2d(b.Start);
            var bD = t2d(b.Dir);
            var bT = t2d(b.Tangent);

            widthA /= 2;
            widthB /= 2;

            var lenA = get2DLength(a.Tangent.y, a.Length);
            var lenB = get2DLength(b.Tangent.y, b.Length);

            if (mode == IntersectionMode.Edge)
            {
                var bC = bP + bD * 0.5f;
                var aC = aP + aD * 0.5f;

                var signA = Mathf.Sign(Vector2.Dot(bC - aC, aT));
                var signB = Mathf.Sign(Vector2.Dot(aC - bC, bT));



                if (intersectsRays(aP, aD, aT, signA * widthA, lenA, bP, bD, bT, signB * widthB, lenB, out offsetA, out offsetB))
                {
                    return(true);
                }
            }
            else
            {
                if (intersectsRays(aP, aD, aT, 0, lenA, bP, bD, bT, 0, lenB, out offsetA, out offsetB))
                {
                    return(true);
                }
            }

            offsetB = offsetA = float.NaN;
            return(false);
        }
예제 #2
0
        private static bool intersectsArcLinear(ArcLoftPath a, float widthA, LinearPath b, float widthB, IntersectionMode mode, out float offsetA, out float offsetB)
        {
            widthA /= 2;
            widthB /= 2;

            if (a.Normal.y > 0.99999f)
            {
                // perfect circle

                var bDirLen = b.Length;
                var bStart  = b.Start - a.Center;
                var bDir    = b.Dir * bDirLen;
                var bTan    = b.Tangent * widthB;

                var center = a.Center;

                center.y = a.StartPoint.y;

                var radius = a.Radius;


                if (mode == IntersectionMode.Edge)
                {
                    if (intersectsEllipseEdge(a, bStart, bDir, bTan, center, bDirLen, widthB, radius, radius, out offsetA, out offsetB))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (intersectEllipseCenter(a, out offsetA, out offsetB, center, radius, radius, bDirLen, bStart, bDir))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                Vector3 center, axisX, axisY;
                float   radiusX, radiusY;
                get2DEllipse(a, out center, out axisX, out axisY, out radiusX, out radiusY);

                var bDirLen = get2DLength(b.Dir.y, b.Length);
                var bStart  = project(b.Start - center, axisX, axisY);
                var bDir    = project(b.Dir * bDirLen, axisX, axisY);
                var bTan    = project(b.Tangent * widthB, axisX, axisY);

                var aStart = project(a.StartPoint, axisX, axisY);

                //DebugUtils.DrawEllipse(Vector3.zero, radiusX + widthA, radiusY + widthA, Color.cyan);
                //DebugUtils.DrawEllipse(Vector3.zero, radiusX, radiusY, Color.yellow);
                //DebugUtils.DrawEllipse(Vector3.zero, radiusX - widthA, radiusY - widthA, Color.magenta);


                if (mode == IntersectionMode.Edge)
                {
                    if (intersectsEllipseEdge(a, bStart, bDir, bTan, center, bDirLen, widthB, radiusX, radiusY, out offsetA, out offsetB))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (intersectEllipseCenter(a, out offsetA, out offsetB, center, radiusX, radiusY, bDirLen, bStart, bDir))
                    {
                        return(true);
                    }
                }
            }

            offsetB = offsetA = float.NaN;
            return(false);
        }