예제 #1
0
 public LineSeg(Point2D a, Point2D b)
 {
     p[0] = a;
     p[1] = b;
 }
예제 #2
0
 public Extent2D(double minx, double miny, double maxx, double maxy)
 {
     min    = new Point2D(minx, miny);
     max    = new Point2D(maxx, maxy);
     IsNull = false;
 }
예제 #3
0
 public bool IsPointIn(Point2D point)
 {
     return(point.X >= min.X && point.X <= max.X && point.Y >= min.Y && point.Y <= max.Y);
 }
예제 #4
0
 public Extent2D(Point2D p1, Point2D p2)
 {
     min    = new Point2D(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y));
     max    = new Point2D(Math.Max(p1.X, p2.X), Math.Max(p1.Y, p2.Y));
     IsNull = false;
 }
예제 #5
0
 public Extent2D(IEnumerable <Point2D> pts)
 {
     min    = new Point2D(pts.Min(p => p.X), pts.Min(p => p.Y));
     max    = new Point2D(pts.Max(p => p.X), pts.Max(p => p.Y));
     IsNull = false;
 }
예제 #6
0
        public double DistToPoint(Point2D p)
        {
            Point2D foot;

            return(DistToPoint(p, out foot));
        }
예제 #7
0
        public double GetDistAtPoint(Point2D p)
        {
            double distance = 0;
            bool   isOnLine = false;

            if (points.Count == 0)
            {
                return(-1);
            }
            else if (points.Count == 1)
            {
                return(Math.Sqrt((p.X - points[0].X) * (p.X - points[0].X) + (p.Y - points[0].Y) * (p.Y - points[0].Y)));
            }
            else
            {
                int count = points.Count;
                for (int i = 0; i < count - 1; i++)
                {
                    if (points[i].X == points[i + 1].X && p.X == points[i].X)
                    {
                        if ((p.Y - points[i].Y) * (p.Y - points[i + 1].Y) <= 0)
                        {
                            distance = distance + Math.Sqrt((p.X - points[i].X) * (p.X - points[i].X) + (p.Y - points[i].Y) * (p.Y - points[i].Y));
                            isOnLine = true;
                            break;
                        }
                        else
                        {
                            isOnLine = false;
                            break;
                        }
                    }

                    else if (points[i].Y == points[i + 1].Y && p.Y == points[i].Y)
                    {
                        if ((p.X - points[i].X) * (p.X - points[i + 1].X) <= 0)
                        {
                            distance = distance + Math.Sqrt((p.X - points[i].X) * (p.X - points[i].X) + (p.Y - points[i].Y) * (p.Y - points[i].Y));
                            isOnLine = true;
                            break;
                        }
                        else
                        {
                            isOnLine = false;
                            break;
                        }
                    }

                    else
                    {
                        if ((p.Y - points[i].Y) / (p.X - points[i].X) == (p.Y - points[i + 1].Y) / (p.X - points[i + 1].X) && (p.Y - points[i].Y != 0) && (points[i + 1].X - points[i].X) * (p.X - points[i].X) >= 0)
                        {
                            distance = distance + Math.Sqrt((p.X - points[i].X) * (p.X - points[i].X) + (p.Y - points[i].Y) * (p.Y - points[i].Y));
                            isOnLine = true;
                            break;
                        }
                        else
                        {
                            distance = distance + Math.Sqrt((points[i + 1].X - points[i].X) * (points[i + 1].X - points[i].X) + (points[i + 1].Y - points[i].Y) * (points[i + 1].Y - points[i].Y));
                        }
                    }
                }
            }

            if (!isOnLine)
            {
                distance = -1;
            }

            return(distance);
        }
예제 #8
0
 public void Insert(int index, Point2D p)
 {
     points.Insert(index, p);
 }
예제 #9
0
 public Point2D TransformBack(Point2D p)
 {
     return(new Point2D(p.X / ScaleX21 + X21, p.Y / ScaleY21 + Y21));
 }
예제 #10
0
 public Point2D Transform(Point2D p)
 {
     return(new Point2D((p.X - X21) * ScaleX21, (p.Y - Y21) * ScaleY21));
 }