Пример #1
0
        public double PointToSegDist(zhixian a, point c)
        {
            double b = a.k * c.X - c.Y + a.b;
            double d = Math.Sqrt(a.k * a.k + 1);

            return(Math.Abs(b / d));
        }
Пример #2
0
        //求两直线垂直k1和k2相乘=-1
        public point jiaodian(zhixian a, zhixian b)
        {
            point p = new point();

            p.X = (a.b - b.b) / (b.k - a.k);
            p.Y = a.k * p.X + a.b;
            return(p);
        }
Пример #3
0
        //算直线的k,b
        public zhixian zx(point a, point b)
        {
            zhixian zhix = new zhixian();

            zhix.k = (b.Y - a.Y) / (b.X - a.X);
            zhix.b = a.Y - zhix.k * a.X;
            return(zhix);
        }
Пример #4
0
        public bool zxjgd(zhixian a, point[] p, point b)
        {
            bool Bool = true;

            for (int i = 0; i < p.Length - 2; i++)
            {
                if (!jiaodian(a, zx(p[i], p[i + 1]), b))
                {
                    Bool = false;
                }
            }
            return(Bool);//如果焦点不是本点输出true
        }
Пример #5
0
        public bool jiaodian(zhixian a, zhixian b, point c)
        {
            point p = new point();

            p.X = (a.b - b.b) / (b.k - a.k);
            p.Y = a.k * p.X + a.b;
            if (p.X == c.X && p.Y == c.Y)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #6
0
        //角平分线
        public zhixian zx(zhixian a, zhixian b, point c, point[] p, point d)
        {
            zhixian zhix = new zhixian();

            zhix.k = (a.k * b.k - 1 + Math.Sqrt(((1 - a.k * b.k) * (1 - a.k * b.k)) + ((a.k + b.k) * (a.k + b.k)))) / (a.k + b.k);
            zhix.b = c.Y - zhix.k * c.X;
            if (zxjgd(zhix, p, d))
            {
                return(zhix);
            }
            else
            {
                zhix.k = (a.k * b.k - 1 - Math.Sqrt(((1 - a.k * b.k) * (1 - a.k * b.k)) + ((a.k + b.k) * (a.k + b.k)))) / (a.k + b.k);
                zhix.b = c.Y - zhix.k * c.X;
                return(zhix);
            }
        }
Пример #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            double[] mj = new double[bianshu];
            double   R2;
            int      min = 0;

            yuan[] yan = new yuan[bianshu];
            bool   b   = true;

            point[] point1 = new point[points.Length + 3];
            for (int q = 0; q < points.Length; q++)
            {
                point1[q].X = points[q].X;
                point1[q].Y = points[q].Y;
            }
            point1[points.Length]     = point1[0];//将第一个加到最后一个上面
            point1[points.Length + 1] = point1[1];
            point1[points.Length + 2] = point1[2];
            for (int i = 0; i < points.Length; i++)
            {
                zhixian z1 = new zhixian();
                z1 = wj.zx(wj.zx(point1[i], point1[i + 1]), wj.zx(point1[i + 1], point1[i + 2]), point1[i + 1], point1, point1[i + 1]);
                zhixian z2 = new zhixian();
                z2 = wj.zx(wj.zx(point1[i + 1], point1[i + 2]), wj.zx(point1[i + 2], point1[i + 3]), point1[i + 2], point1, point1[i + 2]);

                yuan y = new yuan();
                y = wj.neiqie(wj.jiaodian(z1, z2), point1[i], point1[i + 1]);
                for (int n = 0; n < points.Length; n++)
                {
                    R2 = wj.banjing(y.p, point1[n]);
                    if (y.R > R2)
                    {
                        b = false;
                        break;
                    }
                    else
                    {
                        b = true;
                    }
                }
                if (!b)
                {
                    continue;
                }
                mj[i]  = y.mianji;
                yan[i] = y;
            }
            for (int j = 0; j < mj.Length; j++)
            {
                if (paidxu(chongpai(mj)) == mj[j])
                {
                    min = j;
                }
            }
            label1.Text = "外接圆的X坐标:" + yan[min].p.X + "  " + "外接圆的Y坐标:" + yan[min].p.Y + "  " + "外接圆的半径:" + yan[min].R;
            Graphics gra = this.pictureBox1.CreateGraphics();

            gra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            Pen pen = new Pen(Color.Pink);                                                                                                            //画笔颜色

            gra.DrawEllipse(pen, (int)yan[min].p.X - (int)yan[min].R, (int)yan[min].p.Y - (int)yan[min].R, (int)yan[min].R * 2, (int)yan[min].R * 2); //画椭圆的方法,x坐标、y坐标、宽、高,如果是100,则半径为50
        }