Beispiel #1
0
        public bool Intersects(FloatCircle circle, out float overlap)
        {
            var dx       = circle.X - X;
            var dy       = circle.Y - Y;
            var mSquared = dx * dx + dy * dy;
            var r        = Radius + circle.Radius;
            var rSquared = (r) * (r);



            overlap = r - (float)Math.Sqrt(mSquared);

            return(mSquared <= rSquared);
        }
Beispiel #2
0
        private Vector2f[] IntersectionPoints(FloatLine ray, CircleShape shape)
        {
            var circle = new FloatCircle(shape.Position, shape.Radius);

            var circleDelta = (shape.Position - Position);
            var product     = Direction.Dot(circleDelta);

            if (product <= 0) // if ray is facing in the opposite direction of the circle
            {
                return(Array.Empty <Vector2f>());
            }

            return(ray.Intersects(circle));
        }
Beispiel #3
0
        public          Vector2f[] Intersects(FloatCircle circle)
        {
            var circlePos = new Vector2f(circle.X, circle.Y);
            var r         = circle.Radius;
            var p1        = P1 - circlePos; // translate p1 to circle local space
            var p2        = P2 - circlePos; // translate p2 to circle local space
            var d         = p2 - p1;

            var a = d.SqrLength();
            var b = 2 * ((d.X * p1.X) + (d.Y * p1.Y));
            var c = p1.SqrLength() - (r * r);

            var delta = b * b - (4 * a * c);

            if (delta < 0)
            {
                return new Vector2f[] {}
            }
            ;

            if (delta == 1)
            {
                var u = -b / (2 * a);

                var intersection = P1 + (u * d);
                return(new[] { intersection });
            }

            var sqrDelta = -Math.Sqrt(delta);
            var u1       = (float)(-b - sqrDelta) / (2 * a);
            var u2       = (float)(-b + sqrDelta) / (2 * a);

            var intersection1 = P1 + (u1 * d);
            var intersection2 = P1 + (u2 * d);

            return(new[] { intersection1, intersection2 });
        }
Beispiel #4
0
        public T[] QueryRange(FloatCircle boundary)
        {
            var rect = new FloatRect(
                boundary.X - boundary.Radius,
                boundary.Y - boundary.Radius,
                boundary.Radius,
                boundary.Radius
                );

            if (!_boundary.Intersects(rect))
            {
                return(Array.Empty <T>());
            }

            var inRange = new List <T>();

            _data.ForEach(datum =>
            {
                if (boundary.Contains(datum.Point.X, datum.Point.Y))
                {
                    inRange.Add(datum.Data);
                }
            });

            if (_northWest == null)
            {
                return(inRange.ToArray());
            }

            inRange.AddRange(_northEast.QueryRange(boundary));
            inRange.AddRange(_northWest.QueryRange(boundary));
            inRange.AddRange(_southEast.QueryRange(boundary));
            inRange.AddRange(_southWest.QueryRange(boundary));

            return(inRange.ToArray());
        }
Beispiel #5
0
        //**********************************************************
        //** methods:
        //**********************************************************

        public bool Intersects(FloatCircle circle) => Intersects(circle, out _);