Esempio n. 1
0
        private int Orientation(points p1, points p2, points p)
        {
            int orin = (int)((p2.X - p1.X) * (p.Y - p1.Y) - (p.X - p1.X) * (p2.Y - p1.Y));

            if (orin > 0)
            {
                return(-1);
            }
            if (orin < 0)
            {
                return(1);
            }

            return(0);
        }
Esempio n. 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            //           resetFrameBuffer();
            if (pointLocation.Length < 3)
            {
                throw new ArgumentException("You need at least 3 points");
            }
            while (tempForConvex.Count >= 3)
            {
                points min = (points)tempForConvex[0];
                foreach (points x in tempForConvex)
                {
                    if (x.X < min.X)
                    {
                        min = x;
                    }
                }

                List <points> hull = new List <points>();
                points        vEndpoint;
                points        vpointOnHull = min;
                do
                {
                    hull.Add(vpointOnHull);
                    vEndpoint = (points)tempForConvex[0];

                    for (int j = 1; j < tempForConvex.Count; j++)
                    {
                        if (vpointOnHull == vEndpoint || Orientation(vpointOnHull, vEndpoint, (points)tempForConvex[j]) == -1)
                        {
                            vEndpoint = (points)tempForConvex[j];
                        }
                    }
                    vpointOnHull = vEndpoint;
                } while (vEndpoint != hull[0]);

                Pen      drawingPen = new Pen(Brushes.Crimson, lineSize);
                points[] tempCH     = new points[hull.Count];
                int      count      = 0;
                foreach (points x in hull)
                {
                    tempCH[count] = x;
                    count++;
                    output += x.X + " " + x.Y + "\r\n";
                }
                foreach (points x in hull)
                {
                    tempForConvex.Remove(x);
                }
                Graphics g = Graphics.FromImage(aBitMap);
                System.Drawing.SolidBrush aBrsh = new System.Drawing.SolidBrush(Color.Black);
                for (int i = 0; i < tempCH.Length - 1; i++)
                {
                    g.DrawLine(drawingPen, tempCH[i].X * scale, tempCH[i].Y * scale, tempCH[i + 1].X * scale, tempCH[i + 1].Y * scale);
                }
                g.DrawLine(drawingPen, tempCH[tempCH.Length - 1].X * scale, tempCH[tempCH.Length - 1].Y * scale, tempCH[0].X * scale, tempCH[0].Y * scale);
                drawingPen.Dispose();
                for (int i = 0; i < pointLocation.GetLength(0); i++)
                {
                    g.FillEllipse(aBrsh, (float)(pointLocation[i].X * scale) - dotSize / 2.0F, (float)(pointLocation[i].Y * scale) - dotSize / 2.0F, dotSize, dotSize);
                }
                output += "\r\n";
            }
            picBox.Image = aBitMap;
        }