public void Intersect_TwoPoints()
        {
            var   segment = new Segment2();
            var   circle  = new Circle2();
            float offset  = 1;

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int radius = 1; radius < 12; radius += 10)
                {
                    circle.radius = radius;
                    for (int segmentAngle = 0; segmentAngle < 360; segmentAngle += 10)
                    {
                        Vector2 direction = Vector2.down.RotateCW(segmentAngle);
                        Vector2 expectedA = circle.center - direction * circle.radius;
                        Vector2 expectedB = circle.center + direction * circle.radius;
                        segment.a = expectedA;
                        segment.b = expectedB;
                        True_IntersectTwoPoints(segment, circle, segment.a, segment.b);

                        segment.a = circle.center - direction * (circle.radius + offset);
                        segment.b = circle.center + direction * (circle.radius + offset);
                        True_IntersectTwoPoints(segment, circle, expectedA, expectedB);

                        expectedA = circle.GetPoint(segmentAngle + 45);
                        expectedB = circle.GetPoint(segmentAngle + 135);
                        segment.a = expectedA;
                        segment.b = expectedB;
                        True_IntersectTwoPoints(segment, circle, expectedA, expectedB);

                        direction = (expectedB - expectedA).normalized;
                        segment.a = expectedA - direction * 0.1f;
                        segment.b = expectedB + direction * 0.1f;
                        True_IntersectTwoPoints(segment, circle, expectedA, expectedB);
                    }
                }
            }
        }
示例#2
0
        public void Intersect_OnePoint()
        {
            var line   = new Line2();
            var circle = new Circle2(Vector2.zero, 5);

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int lineAngle = 0; lineAngle < 360; lineAngle += 15)
                {
                    line.origin    = circle.GetPoint(lineAngle);
                    line.direction = Vector2.right.RotateCW(lineAngle);
                    True_Intersect(line, circle, line.origin);
                }
            }
        }
        public void Distance_OnCircle()
        {
            var circle = new Circle2();

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int radius = 1; radius < 22; radius += 10)
                {
                    circle.radius = radius;
                    for (int angle = 0; angle < 360; angle += 10)
                    {
                        AreEqual_Distance(circle, circle.GetPoint(angle));
                    }
                }
            }
        }
        public void Intersect_OnCircle()
        {
            var circle = new Circle2();

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int radius = 11; radius < 42; radius += 10)
                {
                    circle.radius = radius;
                    for (int angle = 0; angle < 360; angle += 10)
                    {
                        True_Intersect(circle, circle.GetPoint(angle));
                    }
                }
            }
        }
        public void ClosestPoint_OnCircle()
        {
            var circle = new Circle2();

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int radius = 1; radius < 22; radius += 10)
                {
                    circle.radius = radius;
                    for (int angle = 0; angle < 360; angle += 10)
                    {
                        Vector2 point = circle.GetPoint(angle);
                        AreEqual_ClosestPoint(circle, point, point);
                    }
                }
            }
        }
        public void ClosestPoint_Separate()
        {
            var circle = new Circle2();

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int radius = 1; radius < 22; radius += 10)
                {
                    circle.radius = radius;
                    for (int angle = 0; angle < 360; angle += 10)
                    {
                        Vector2 point    = circle.center + Geometry.PointOnCircle2(circle.radius + 1, angle);
                        Vector2 expected = circle.GetPoint(angle);
                        AreEqual_ClosestPoint(circle, point, expected);
                    }
                }
            }
        }
示例#7
0
        public void Distance_OnePoint()
        {
            var line   = new Line2();
            var circle = new Circle2(Vector2.zero, 5);

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int lineAngle = 0; lineAngle < 360; lineAngle += 15)
                {
                    Vector2 origin = circle.GetPoint(lineAngle);
                    line.origin    = origin;
                    line.direction = Vector2.right.RotateCW(lineAngle);
                    AreEqual_Distance(line, circle);
                    line.origin = origin - line.direction;
                    AreEqual_Distance(line, circle);
                    line.origin = origin + line.direction;
                    AreEqual_Distance(line, circle);
                }
            }
        }
示例#8
0
        public void ClosestPoints_OnePoint()
        {
            var line   = new Line2();
            var circle = new Circle2(Vector2.zero, 4);

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int lineAngle = 0; lineAngle < 360; lineAngle += 15)
                {
                    Vector2 origin = circle.GetPoint(lineAngle);
                    line.origin    = origin;
                    line.direction = Vector2.right.RotateCW(lineAngle);
                    ClosestPoints_OnePoint(line, circle, origin);
                    line.origin = origin - line.direction;
                    ClosestPoints_OnePoint(line, circle, origin);
                    line.origin = origin + line.direction;
                    ClosestPoints_OnePoint(line, circle, origin);
                }
            }
        }
        public void Intersect_OutsideOnePoint()
        {
            var circleA = new Circle2();
            var circleB = new Circle2();

            foreach (var center in originPoints2)
            {
                circleA.center = center;
                for (int radius = 1; radius < 22; radius += 10)
                {
                    circleA.radius = radius;
                    circleB.radius = radius + 1;

                    for (int angle = 0; angle < 360; angle += 10)
                    {
                        circleB.center = circleA.center + Geometry.PointOnCircle2(circleA.radius + circleB.radius, angle);
                        True_Intersect(circleA, circleB, circleA.GetPoint(angle));
                    }
                }
            }
        }
        public void ClosestPoints_Separate()
        {
            var   circleA  = new Circle2();
            var   circleB  = new Circle2();
            float distance = 1;

            foreach (var center in originPoints2)
            {
                circleA.center = center;
                for (int radius = 1; radius < 12; radius += 10)
                {
                    circleA.radius = radius;
                    circleB.radius = radius + 1;

                    for (int angle = 0; angle < 360; angle += 10)
                    {
                        circleB.center = circleA.center + Geometry.PointOnCircle2(circleA.radius + circleB.radius + distance, angle);
                        AreEqual_ClosestPoints(circleA, circleB, circleA.GetPoint(angle), circleB.GetPoint(angle - 180));
                    }
                }
            }
        }
        public void ClosestPoints_OutsideOnePoint()
        {
            var circleA = new Circle2();
            var circleB = new Circle2();

            foreach (var center in originPoints2)
            {
                circleA.center = center;
                for (int radius = 1; radius < 22; radius += 10)
                {
                    circleA.radius = radius;
                    circleB.radius = radius + 1;

                    for (int angle = 0; angle < 360; angle += 10)
                    {
                        circleB.center = circleA.center + Geometry.PointOnCircle2(circleA.radius + circleB.radius, angle);
                        Vector2 expected = circleA.GetPoint(angle);
                        AreEqual_ClosestPoints(circleA, circleB, expected, expected);
                    }
                }
            }
        }
示例#12
0
        public void ClosestPoints_Separate()
        {
            var   ray      = new Ray2D();
            var   circle   = new Circle2();
            float distance = 1;

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int radius = 1; radius < 22; radius += 10)
                {
                    circle.radius = radius;
                    for (int originAngle = 0; originAngle < 360; originAngle += 10)
                    {
                        Vector2 origin   = circle.center + Geometry.PointOnCircle2(circle.radius + distance, originAngle);
                        Vector2 left     = Vector2.left.RotateCW(originAngle).normalized;
                        Vector2 right    = -left;
                        Vector2 onCircle = circle.GetPoint(originAngle);

                        ray.origin    = origin + left;
                        ray.direction = right;
                        AreEqual_ClosestPoints(ray, circle, origin, onCircle);

                        ray.origin    = origin + right;
                        ray.direction = left;
                        AreEqual_ClosestPoints(ray, circle, origin, onCircle);

                        for (int directionAngle = 0; directionAngle <= 180; directionAngle += 10)
                        {
                            ray.origin    = origin;
                            ray.direction = left.RotateCW(directionAngle);
                            AreEqual_ClosestPoints(ray, circle, ray.origin, onCircle);
                        }
                    }
                }
            }
        }
        public void Intersect_OnePointInCircle()
        {
            var segment = new Segment2();
            var circle  = new Circle2();

            foreach (var center in originPoints2)
            {
                circle.center = center;
                for (int radius = 1; radius < 12; radius += 10)
                {
                    circle.radius = radius;
                    for (int segmentAngle = 0; segmentAngle < 360; segmentAngle += 10)
                    {
                        Vector2 down = Vector2.down.RotateCW(segmentAngle);
                        segment.a = circle.center;
                        segment.b = circle.center + down * circle.radius * 2;
                        Vector2 onCircle = circle.center + down * circle.radius;
                        True_IntersectPoint(segment, circle, onCircle);

                        segment.a = circle.center + down * 0.5f;
                        segment.b = circle.center + down * circle.radius * 2;
                        True_IntersectPoint(segment, circle, onCircle);

                        onCircle = circle.GetPoint(segmentAngle + 135);
                        float distance = Mathf.Sqrt(2 * circle.radius);
                        segment.a = onCircle - down * distance * 0.1f;
                        segment.b = onCircle + down * circle.radius * 2;
                        True_IntersectPoint(segment, circle, onCircle);

                        segment.a = onCircle - down * distance * 0.9f;
                        segment.b = onCircle + down * circle.radius * 2;
                        True_IntersectPoint(segment, circle, onCircle);
                    }
                }
            }
        }
示例#14
0
        public void GetPoint()
        {
            for (int centerAngle = 0; centerAngle < 360; centerAngle += 10)
            {
                Vector2 center = Geometry.PointOnCircle2(100, centerAngle);
                for (int radius = 1; radius < 32; radius += 10)
                {
                    var     circle = new Circle2(center, radius);
                    Vector2 point0 = center + Vector2.up * radius;
                    AreEqual(circle.GetPoint(0), point0);
                    AreEqual(circle.GetPoint(360), point0);
                    AreEqual(circle.GetPoint(-360), point0);

                    Vector2 point90 = center + Vector2.right * radius;
                    AreEqual(circle.GetPoint(90), point90);
                    AreEqual(circle.GetPoint(450), point90);
                    AreEqual(circle.GetPoint(-270), point90);

                    Vector2 point180 = center + Vector2.down * radius;
                    AreEqual(circle.GetPoint(180), point180);
                    AreEqual(circle.GetPoint(540), point180);
                    AreEqual(circle.GetPoint(-180), point180);

                    Vector2 point270 = center + Vector2.left * radius;
                    AreEqual(circle.GetPoint(270), point270);
                    AreEqual(circle.GetPoint(630), point270);
                    AreEqual(circle.GetPoint(-90), point270);
                }
            }
        }