Exemplo n.º 1
0
        /// <summary>
        /// Convert a Robot contour geometry to a Nucleus polycurve
        /// </summary>
        /// <param name="contour"></param>
        /// <returns></returns>
        public static PolyCurve Convert(RobotGeoContour contour)
        {
            PolyCurve result = new PolyCurve();
            RobotGeoSegmentCollection segments     = contour.Segments as RobotGeoSegmentCollection;
            RobotGeoSegment           firstSegment = segments.Get(1);
            Vector lastPt = Convert(firstSegment.P1);

            for (int i = 2; i <= segments.Count; i++)
            {
                RobotGeoSegment segment = segments.Get(i);
                if (segment.Type == IRobotGeoSegmentType.I_GST_ARC)
                {
                    RobotGeoSegmentArc arcSegment = (RobotGeoSegmentArc)segment;
                    Vector             endPt      = Convert(arcSegment.P2);
                    Arc arc = new Arc(lastPt, Convert(arcSegment.P1), endPt);
                    result.Add(arc);
                    lastPt = endPt;
                }
                else
                {
                    Vector endPt = Convert(segment.P1);
                    Line   line  = new Line(lastPt, endPt);
                    result.Add(line);
                    lastPt = endPt;
                }
            }
            result.Close();
            return(result);
        }
Exemplo n.º 2
0
        public void AreaCalculationTest()
        {
            var polyCrv = new PolyCurve(new Line(0, 0, 10, 10));

            polyCrv.AddArc(new Vector(10, 0));
            polyCrv.Add(new PolyLine(new Vector(10, 0), new Vector(5, 0), new Vector(5, -5)));
            polyCrv.Close();

            Vector centroid;
            double area = polyCrv.CalculateEnclosedArea(out centroid);

            Assert.AreEqual(205.309725, area, 0.0001);
        }
Exemplo n.º 3
0
        public void SubdomainByCentreTest2()
        {
            var polyCrv = new PolyCurve(new Line(0, 0, 10, 10));

            polyCrv.AddArc(new Vector(10, 0));
            polyCrv.Add(new PolyLine(new Vector(10, 0), new Vector(5, 0), new Vector(5, -5)));
            polyCrv.Close();

            var   domain = polyCrv.SubdomainByCentre(0.01, 20);
            Curve subCrv = polyCrv.Extract(domain);

            Assert.AreEqual(20, subCrv.Length, 0.00001);
        }