예제 #1
0
        public static MLine IntersectLine(MCircle c1, MCircle c2)
        {
            MPoint[] points = new MPoint[2];
            points[0] = new MPoint(Double.NaN, Double.NaN);
            points[1] = new MPoint(Double.NaN, Double.NaN);

            double d = MPoint.Distance(c1.Center, c2.Center);

            if (d > c1.Radius + c2.Radius)
            {
                return(null);
            }

            if (d < Math.Abs(c1.Radius - c2.Radius))
            {
                return(null);
            }

            if (Math.Abs(d) < Double.Epsilon && Math.Abs(c1.Radius - c2.Radius) < Double.Epsilon)
            {
                return(null);
            }

            double a = (c1.Radius * c1.Radius - c2.Radius * c2.Radius + d * d) / 2 * d;
            double h = Math.Sqrt(c1.Radius * c1.Radius - a * a);

            MPoint p2 = c1.Center + (c1.Center - c2.Center) * a / d;

            points[0] = new MPoint(p2.X + h * (c2.Center.Y - c1.Center.Y) / d, p2.Y - h * (c2.Center.X - c1.Center.X) / d);
            points[1] = new MPoint(p2.X - h * (c2.Center.Y - c1.Center.Y) / d, p2.Y + h * (c2.Center.X - c1.Center.X) / d);
            return(new MLine(points[0], points[1]));
        }
예제 #2
0
 protected bool Equals(MPoint other)
 {
     return(X.Equals(other.X) && Y.Equals(other.Y));
 }
예제 #3
0
 public static double Distance(MPoint p1, MPoint p2)
 {
     return(Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y)));
 }
예제 #4
0
 public Boolean onCircle(MPoint p)
 {
     return(Math.Abs(MPoint.Distance(p, Center) - Radius) < Double.Epsilon);
 }
예제 #5
0
 public MCircle(MPoint center, double radius)
 {
     Center = center;
     Radius = radius;
 }
예제 #6
0
 public MLine(Point p1, MPoint p2)
 {
     M = (p1.Y - p2.Y) / (p1.X - p2.X);
     B = p1.Y - M * p1.X;
 }