コード例 #1
0
        private void DrawPanel()
        {
            int      width  = pnlImage.Width;
            int      height = pnlImage.Height;
            Bitmap   image  = new Bitmap(width, height);
            Graphics g      = Graphics.FromImage(image);

            g.Clear(Color.Black);
            float     count  = 4;
            float     length = 75;
            UnitPoint p1     = new UnitPoint(20, 90);
            UnitPoint p2     = new UnitPoint(35, 65);
            UnitPoint p3     = new UnitPoint(50, 90);

            UnitPoint intersecte1 = HitUtil.GetLinePointByDistance(p2, p1, length, false);
            UnitPoint intersecte2 = HitUtil.GetLinePointByDistance(p2, p3, length, false);

            List <UnitPoint> pointBers = new List <UnitPoint>();

            pointBers.Add(p2);
            pointBers.Add(intersecte1);
            pointBers.Add(intersecte2);
            pointBers.Add(p2);

            List <UnitPoint> pointLines = new List <UnitPoint>();

            pointLines.Add(p1);
            pointLines.Add(p2);
            pointLines.Add(p3);

            for (int i = 0; i < count; i++)
            {
                var ps = pointBers.Select(e => new PointF((float)(e.X + Math.Abs(p1.X - p3.X) * i), (float)e.Y));
                g.DrawBeziers(Pens.LimeGreen, ps.ToArray());
            }
            for (int i = 0; i < count; i++)
            {
                var ps = pointLines.Select(e => new PointF((float)(e.X + Math.Abs(p1.X - p3.X) * i), (float)e.Y));
                g.DrawLines(Pens.LimeGreen, ps.ToArray());
            }
            using (Graphics tg = pnlImage.CreateGraphics())
            {
                tg.DrawImage(image, 0, 0);   //把画布贴到画面上
            }
        }
コード例 #2
0
ファイル: BulgeHelper.cs プロジェクト: liyangTeam/WSXCut
        public static UnitPoint GetCenterByBulgeAndTwoPoints(UnitPoint p1, UnitPoint p2, double bulge)
        {
            //UnitPoint centerPoints;
            //double chord = HitUtil.Distance(p1, p2);
            //double radius = chord / (2 * Math.Sin(2 * Math.Atan(Math.Abs(bulge))));
            //double c1 = (p2.X * p2.X - p1.X * p1.X + p2.Y * p2.Y - p1.Y * p1.Y) / (2 * (p2.X - p1.X));
            //double c2 = (p2.Y - p1.Y) / (p2.X - p1.X);
            //double A = (c2 * c2 + 1);
            //double B = (2 * p1.X * c2 - 2 * c1 * c2 - 2 * p1.Y);
            //double C = p1.X * p1.X - 2 * p1.X * c1 + c1 * c1 + p1.Y * p1.Y - radius * radius;
            //double y1 = (-B + Math.Sqrt(B * B - 4 * A * C)) / (2 * A);
            //double y2 = (-B - Math.Sqrt(B * B - 4 * A * C)) / (2 * A);
            //double x1 = c1 - c2 * y1;
            //double x2 = c1 - c2 * y2;
            //UnitPoint centerPoints1 = new UnitPoint(x1, y1);
            //UnitPoint centerPoints2 = new UnitPoint(x2, y2);
            //double err1 = IsCorrectCenter(centerPoints1, radius, bulge, p1, p2);
            //double err2 = IsCorrectCenter(centerPoints2, radius, bulge, p1, p2);
            //centerPoints = err1 < err2 ? centerPoints1 : centerPoints2;
            //return centerPoints;


            UnitPoint centerPoints = new UnitPoint();
            double    chord        = HitUtil.Distance(p1, p2);
            double    radius       = chord / (2 * Math.Sin(2 * Math.Atan(Math.Abs(bulge))));
            //1.求p1,p2的中间点
            UnitPoint midPoint = HitUtil.GetLinePointByDistance(p1, p2, chord / 2, true);
            double    length   = Math.Sqrt(Math.Pow(radius, 2) - Math.Pow(chord / 2, 2));
            //2.求等距离的垂线点
            var centers = DrawingOperationHelper.GetLinePointByVerticalLine(midPoint, p1, length);
            //3.筛选圆心坐标
            double err1 = IsCorrectCenter(centers.Item1, radius, bulge, p1, p2);
            double err2 = IsCorrectCenter(centers.Item2, radius, bulge, p1, p2);

            centerPoints = err1 < err2 ? centers.Item1 : centers.Item2;
            return(centerPoints);
        }