[TestCase(0, 0, 50, "51, 0", false)] // Point close away from border
        public void ContainsPoint(double xs, double ys, double radius, String point, bool expected)
        {
            var v1 = Vector2.Parse(point);
            var c1 = new Circle2(xs, ys, radius);

            Assert.True(c1.Contains(v1) == expected);
        }
 public static VisualCircle Create(Circle2 circle, Pen pen = null, Brush brush = null)
 {
     return new VisualCircle(circle)
     {
         Pen = pen,
         FillBrush = brush
     };
 }
        public void Constructor(double xs, double ys, double radius)
        {

            var c1 = new Circle2(xs, ys, radius);

            Assert.AreEqual(c1.Radius, radius);
            Assert.AreEqual(c1.MiddlePoint, new Vector2(xs, ys));
            Assert.AreEqual(c1.Area, radius * radius * Math.PI);
        }
Пример #4
0
        public Circle2 ToCircle()
        {
            var c = new Circle2(this.MiddlePoint, this.Radius);

            return(c);
        }
        /// <summary>
        /// Arc-Line Interception
        /// </summary>
        /// <param name="uLine">Line to check</param>
        /// <param name="tolerance"></param>
        /// <returns>Returns the interception Point(s) if the Objects collide</returns>
        private List<Vector2> InterceptLine(LineSegment2 uLine, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            var intersections = new List<Vector2>();

            // Stretch the line on both ends by tolerance
            // TODO Is this still necessary??
            var strechtedLine = (uLine.Clone() as LineSegment2);
            strechtedLine.Stretch(tolerance, Direction.LEFT);
            strechtedLine.Stretch(tolerance, Direction.RIGHT);
            uLine = strechtedLine;


            // Intersect with a circle and test inter points if they lie on our arc
            var circle = new Circle2(this.MiddlePoint, this.Radius);
            foreach (var possiblePnt in circle.Intersect(uLine, tolerance))
            {
                if (this.Contains(possiblePnt, tolerance))
                {
                    intersections.Add(possiblePnt);
                }
            }
            
            return intersections;
        }
 private bool InterceptCircleWith(Circle2 circle, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
 {
     var possibles = this.ToCircle().Intersect(circle, tolerance);
     foreach (var p in possibles)
     {
         if (this.Contains(p, tolerance)) return true;
             
     }
     return false;
 }
        private IEnumerable<Vector2> InterceptCircle(Circle2 circle, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            var intersections = new List<Vector2>();

            var possibles = this.ToCircle().Intersect(circle, tolerance);
            foreach (var p in possibles)
            {
                if (this.Contains(p, tolerance))
                {
                    intersections.Add(p);
                }
            }

            return intersections;
        }
Пример #8
0
 VisualPoint(Circle2 point)
 {
     _point = point;
     _visualPoint = new VisualCircle(_point);
 }
        private bool HasCollision(Circle2 other, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            // Test each line if it has a collision
            var lines = ToLines();

            foreach (var line in lines)
            {
                if (other.HasCollision(line, tolerance))
                {
                    return true; // We have a collision and can stop
                }
            }
            return false;
        }
Пример #10
0
 public Circle2 ToCircle()
 {
     var c = new Circle2(this.MiddlePoint, this.Radius);
     return c;
 }
Пример #11
0
 public VisualCircle(Circle2 circle)
 {
     _circle = circle;
 }
        /// <summary>
        /// Find Circle - Circle Intersectionpoints
        /// </summary>
        /// <param name="cA"></param>
        /// <param name="cB"></param>
        /// <returns></returns>
        private IEnumerable<Vector2> IntersectCircle(Circle2 cA, Circle2 cB)
        {

            var dv = cA.MiddlePoint - cB.MiddlePoint;
            var d2 = dv.X * dv.X + dv.Y * dv.Y;
            var d = Math.Sqrt(d2);

            if (d > cA.Radius + cB.Radius || d < Math.Abs(cA.Radius - cB.Radius))
                return new Vector2[] { }; // no solution

            var a = (cA.Radius2 - cB.Radius2 + d2) / (2 * d);
            var h = Math.Sqrt(cA.Radius2 - a * a);
            var x2 = cA.MiddlePoint.X + a * (cB.MiddlePoint.X - cA.MiddlePoint.X) / d;
            var y2 = cA.MiddlePoint.Y + a * (cB.MiddlePoint.Y - cA.MiddlePoint.Y) / d;

            var paX = x2 + h * (cB.MiddlePoint.Y - cA.MiddlePoint.Y) / d;
            var paY = y2 - h * (cB.MiddlePoint.X - cA.MiddlePoint.X) / d;
            var pbX = x2 - h * (cB.MiddlePoint.Y - cA.MiddlePoint.Y) / d;
            var pbY = y2 + h * (cB.MiddlePoint.X - cA.MiddlePoint.X) / d;

            return new Vector2[] { new Vector2(paX, paY), new Vector2(pbX, pbY) };
        }
 private IEnumerable<Vector2> InterceptCircle(Circle2 other, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
 {
     var interceptions = new List<Vector2>();
     if (InterceptWithCircle(other, tolerance))
     {
         var middlepointDistance = LineSegment2.CalcLenght(this.MiddlePoint, other.MiddlePoint);
         if (middlepointDistance < Math.Abs(this.Radius + other.Radius))
         {
             // circle is contained in other
         }
         else if (middlepointDistance == 0 && (this.Radius == other.Radius))
         {
             // circle are concident -> infinite numbers of intersections
         }
         else
         {
             interceptions.AddRange(IntersectCircle(this, other));
         }
     }
     return interceptions;
 }
 private bool InterceptWithCircle(Circle2 other, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
 {
     var middlepointDistance = LineSegment2.CalcLenght(this.MiddlePoint, other.MiddlePoint);
     var radiusSum = this.Radius + other.Radius;
     return !(middlepointDistance > (radiusSum + tolerance));
 }
Пример #15
0
 public Circle2(Circle2 prototype) {
     Prototype(prototype);
 }
Пример #16
0
 public virtual bool Contains(Vector2 point, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
 {
     return(Circle2.Contains(this.MiddlePoint, this.Radius, point, tolerance));
 }