Exemplo n.º 1
0
        private CompResult ComputeParallelLines(double width, List <MyPoint3D> cartPolygon, LineDefinition lineDef, List <MyPoint3D> intersections, bool addLinesToMap)
        {
            CompResult result = new CompResult();

            while (intersections.Count > 1)
            {
                intersections = intersections.Distinct(new MyPoint3D.MyPoint3D_EqualityComparer()).ToList();
                if (intersections.Min(p => p.Y) == intersections.Max(p => p.Y))
                {
                    intersections.Sort(new MyPoint3D.MyPoint3D_ComparerByX());
                }
                else
                {
                    intersections.Sort(new MyPoint3D.MyPoint3D_ComparerByY());
                }

                for (int i = 0; i < intersections.Count - 1; i += 2)
                {
                    var p1 = intersections[i + 1];
                    var p2 = intersections[i];
                    result.LinesLength += (p1 - p2).Norm;
                    result.LinesCount++;
                    if (addLinesToMap)
                    {
                        AddLineToMap(p1, p2);
                        AddSwathToMap(p1, p2, width);
                    }
                }
                lineDef       = LineDefinition.GetParallelLine(lineDef, width);
                intersections = Utility.GetHeadlandIntersections(cartPolygon, lineDef, width);
            }
            return(result);
        }
Exemplo n.º 2
0
        private AnalysisResult AnalyzeFieldAndShowSwaths(FieldVM polygon, LineDefinition lineDef)
        {
            double processedArea = 0;
            double width         = ImplementWidth;
            var    geoPolygon    = new List <GeoPoint>();

            foreach (var p in polygon.Locations)
            {
                geoPolygon.Add(p.ToGeoPoint());
            }

            List <MyPoint3D> cartPolygon = new List <MyPoint3D>();

            foreach (var p in polygon.Locations)
            {
                cartPolygon.Add(p.ToGeoPoint().ToCart());
            }

            double length = width / 2.0;

            if (Utility.CalculateArea(geoPolygon, false) < 0)
            {
                length = -length;
            }


            List <MyPoint3D> boundary = new List <MyPoint3D>();
            MyPoint3D        prevP    = cartPolygon[0];

            boundary.Add(cartPolygon[0]);
            for (int i = 1; i < cartPolygon.Count; i++)
            {
                if ((prevP - cartPolygon[i]).Norm < 3)
                {
                    continue;
                }
                prevP = cartPolygon[i];
                boundary.Add(cartPolygon[i]);
            }
            if ((boundary.First() - boundary.Last()).Norm < 3)
            {
                boundary.Remove(boundary.Last());
            }

            length = -length;
            List <MyPoint3D> headLand = Utility.ShiftBoundary(length, boundary);

            headLand.Add(headLand.First());
            List <MyPoint3D> innerBoundary = Utility.ShiftBoundary(2 * length, boundary);

            AddHeadLandToMap(headLand);
            AddOuterSwathToMap(boundary, innerBoundary);

            var intersections = Utility.GetHeadlandIntersections(headLand, lineDef, width);

            processedArea += width * ComputeParallelLines(width, headLand, lineDef, intersections, true).LinesLength;

            lineDef        = LineDefinition.GetParallelLine(lineDef, -width);
            intersections  = Utility.GetHeadlandIntersections(headLand, lineDef, width);
            processedArea += width * ComputeParallelLines(-width, headLand, lineDef, intersections, true).LinesLength;
            for (int i = 1; i < headLand.Count; i++)
            {
                processedArea += width * (headLand[i - 1] - headLand[i]).Norm;
            }

            AnalysisResult res = new AnalysisResult();

            res.AppliedArea = processedArea;
            res.FieldArea   = Utility.CalculateArea(geoPolygon);
            return(res);
        }