Ejemplo n.º 1
0
        private Point CalculatorCenter(Point cRc1, Point cRc2, Point cRc3)
        {
            Point midPoint1 = new Point((int)(cRc1.X + cRc2.X) / 2, (int)(cRc1.Y + cRc2.Y) / 2);
            Point midPoint2 = new Point((int)(cRc3.X + cRc2.X) / 2, (int)(cRc3.Y + cRc2.Y) / 2);
            // y = ax+b
            phuongtrinhduongthang dt1 = giahephuongtrinh(cRc1, cRc2);
            phuongtrinhduongthang dt2 = giahephuongtrinh(cRc2, cRc3);

            phuongtrinhvuonggoc(ref dt1, midPoint1);
            phuongtrinhvuonggoc(ref dt2, midPoint2);
            Point result = GetCenter(dt1, dt2);

            return(result);
        }
Ejemplo n.º 2
0
        private Point GetCenter(phuongtrinhduongthang dt1, phuongtrinhduongthang dt2)
        {
            Point center = new Point();

            /*
             * y = a1x + b1 => x = (b2-b1)/ (a1-a2)
             * y = a2x + b2
             *
             */
            center.X = (int)((dt2.b - dt1.b) / (dt1.a - dt2.a));
            center.Y = (int)(dt2.a * center.X + dt2.b);



            return(center);
        }
Ejemplo n.º 3
0
        private phuongtrinhduongthang giahephuongtrinh(Point point1, Point point2)
        {
            phuongtrinhduongthang result = new phuongtrinhduongthang();

            /*
             * y1 = ax1 + b
             * y2 = ax2 + b
             * => a = (y1-y2)/(x1-x2)
             * => b = y1/a*x1
             *
             */
            result.a = (double)(point1.Y - point2.Y) / (point1.X - point2.X);
            result.b = (double)point2.Y - (result.a * point2.X);
            // convert to ax+by+c = 0
            return(result);
        }
Ejemplo n.º 4
0
 private void phuongtrinhvuonggoc(ref phuongtrinhduongthang dtvg, Point mid)
 {
     dtvg.a = -1 / dtvg.a;
     // y = ax+ b
     dtvg.b = mid.Y - dtvg.a * mid.X;
 }