示例#1
0
		/// <summary>
		///     Преобразует набор точек в путь
		/// </summary>
		/// <param name="points">Коллекция точек</param>
		/// <param name="pathKind">Тип пути - Линия(замкнутая/открытая), либо Эллипс</param>
		/// <returns></returns>
		public static string PointsToPath(PointCollection points, PathKind pathKind) {
			var enumerable = points.ToArray();
			if (!enumerable.Any()) {
				return string.Empty;
			}

			switch (pathKind) {
				case PathKind.Ellipse: {
						var radiusX = (enumerable[1].X - enumerable[0].X) / 2;
						var radiusY = (enumerable[2].Y - enumerable[1].Y) / 2;
						var center = new Point(enumerable[1].X - radiusX, enumerable[2].Y - radiusY);
						var geometry = new EllipseGeometry(center: center, radiusX: radiusX, radiusY: radiusY);
						return geometry.GetFlattenedPathGeometry().ToString(CultureInfo.InvariantCulture);
					}
				default: {
						var start = enumerable[0];
						var segments = new List<LineSegment>();
						for (var i = 1; i < enumerable.Length; i++) {
							segments.Add(new LineSegment(new Point(enumerable[i].X, enumerable[i].Y), true));
						}
						var figure = new PathFigure(start, segments, (pathKind == PathKind.ClosedLine));
						var geometry = new PathGeometry();
						geometry.Figures.Add(figure);
						return geometry.ToString(CultureInfo.InvariantCulture);
					}
			}
		}
示例#2
0
 // Checks if 3D points projected to the plane of the polygon are inside the polygon
 public static bool InsidePolygon3D(Point3D[] polyVertices, Point3D projectedPoint)
 {
     PointCollection points = new PointCollection();
     foreach (Point3D point in polyVertices)
     {
         points.Add(new Point(point.X, point.Y));
     }
     return InsidePolygon(points.ToArray(), new Point(projectedPoint.X, projectedPoint.Y));
 }