An arc is a finite line (having a start and end) that is curved as around a circle.
Inheritance: IEdge
        public void PlaneRegion_ShiftList()
        {
            List<ISurface> planes = new List<ISurface>();

            List<LineSegment> polygonLines = new List<LineSegment>();
            polygonLines.Add(new LineSegment(MakePointWithInches(2, 3, 1)));
            polygonLines.Add(new LineSegment(MakePointWithInches(0, 2, 5)));
            polygonLines.Add(new LineSegment(MakePointWithInches(2, 3, 1), MakePointWithInches(0, 2, 5)));
            Polygon polygon = new Polygon(polygonLines);

            List<LineSegment> polygon2Lines = new List<LineSegment>();
            polygon2Lines.Add(new LineSegment(MakePointWithInches(-1, -5, 7)));
            polygon2Lines.Add(new LineSegment(MakePointWithInches(2, 3, 2)));
            polygon2Lines.Add(new LineSegment(MakePointWithInches(2, 3, 2), MakePointWithInches(-1, -5, 7)));
            Polygon polygon2 = new Polygon(polygon2Lines);

            List<IEdge> nonPolygonEdges = new List<IEdge>();
            nonPolygonEdges.Add(new LineSegment(MakePointWithInches(1, 5, 3)));
            nonPolygonEdges.Add(new LineSegment(MakePointWithInches(1, 5, 3), MakePointWithInches(2, 3, 3)));
            Arc arcToadd = new Arc(Point.Origin, MakePointWithInches(2, 3, 3), Direction.Right);
            nonPolygonEdges.Add(arcToadd);
            PlaneRegion nonPolygon = new PlaneRegion(nonPolygonEdges);

            //add them to the generic list
            planes.Add(polygon);
            planes.Add(polygon2);
            planes.Add(nonPolygon);

            Shift shift = new Shift(MakePointWithInches(2, 0, 0));

            List<LineSegment> polygonExpectedLines = new List<LineSegment>();
            polygonExpectedLines.Add(new LineSegment(MakePointWithInches(2, 0, 0), MakePointWithInches(4, 3, 1)));
            polygonExpectedLines.Add(new LineSegment(MakePointWithInches(2, 0, 0), MakePointWithInches(2, 2, 5)));
            polygonExpectedLines.Add(new LineSegment(MakePointWithInches(4, 3, 1), MakePointWithInches(2, 2, 5)));
            Polygon polygonExpected = new Polygon(polygonExpectedLines);

            List<LineSegment> polygon2ExpectedLines = new List<LineSegment>();
            polygon2ExpectedLines.Add(new LineSegment(MakePointWithInches(2, 0, 0), MakePointWithInches(1, -5, 7)));
            polygon2ExpectedLines.Add(new LineSegment(MakePointWithInches(2, 0, 0), MakePointWithInches(4, 3, 2)));
            polygon2ExpectedLines.Add(new LineSegment(MakePointWithInches(4, 3, 2), MakePointWithInches(1, -5, 7)));
            Polygon polygon2Expected = new Polygon(polygon2ExpectedLines);

            List<IEdge> nonPolygonExpectedEdges = new List<IEdge>();
            nonPolygonExpectedEdges.Add(new LineSegment(MakePointWithInches(2, 0, 0), MakePointWithInches(3, 5, 3)));
            nonPolygonExpectedEdges.Add(new LineSegment(MakePointWithInches(3, 5, 3), MakePointWithInches(4, 3, 3)));
            Arc arcExpected = new Arc(MakePointWithInches(2, 0, 0), MakePointWithInches(4, 3, 3), Direction.Right);
            nonPolygonExpectedEdges.Add(arcExpected);
            PlaneRegion nonPolygonExpected = new PlaneRegion(nonPolygonExpectedEdges);

            List<ISurface> resultPlanes = planes.Shift(shift);
            ((Polygon)resultPlanes[0] == polygonExpected).Should().BeTrue();
            ((Polygon)resultPlanes[1] == polygon2Expected).Should().BeTrue();
            ((PlaneRegion)resultPlanes[2] == nonPolygonExpected).Should().BeTrue();
        }  
        public Circle(Point center, Distance radius, Direction normalDirection = null)    
        {
            if (normalDirection == null)
            {
                normalDirection = Direction.Out;
            }
            var vector1 = new Vector(Point.MakePointWithInches(1, 0, 0)).CrossProduct(normalDirection * new Distance(1, Inches));
            var vector2 = new Vector(Point.MakePointWithInches(0, 1, 0)).CrossProduct(normalDirection * new Distance(1, Inches));
            var vector3 = new Vector(Point.MakePointWithInches(0, 0, 1)).CrossProduct(normalDirection * new Distance(1, Inches));
            var chosen = new List<Vector>() { vector1, vector2, vector3 }.MaxBy(v => v.Magnitude);

            var basePoint = center.Translate(chosen.Direction * radius);
            var arc = new Arc(basePoint, basePoint, new Line(center, normalDirection));

            this._Edges = new List<IEdge>() { arc };
            this.NormalLine = new Line(arc.CenterPoint, arc.NormalDirection);
        }
        public void Arc_Properties_Quarter_Circle()
        {
            //make our default arc
            Point basePoint = Point.Origin;
            Point endPoint = Point.MakePointWithInches(3, 3, 4.24264); //sqr(3^2 + 3^2)
            Direction directionAtStart = new Direction(Point.MakePointWithInches(1, 1, 0));

            Arc quarterArc = new Arc(basePoint, endPoint, directionAtStart);

            //test arc length
            Distance arcLength = quarterArc.ArcLength;
            //s = r(theta)
            Distance expectedArclength = new Distance(new Inch(), 4.24264 * Math.PI / 2);
            (arcLength == expectedArclength).Should().BeTrue();

            //test arc area
            Area arcArea = quarterArc.SectorArea;
            //a = (theta)/2 * r^2
            Area expectedArea = new Area(new SquareInch(), (Math.PI / 2) / 2 * (18)); //Pi/2 = 90 degrees, 18 = r^2
            (arcArea == expectedArea).Should().BeTrue();

            //test the arcSegmentArea
            Area arcSegmentArea = quarterArc.SegmentArea;
            //a = r^2 / 2 * (theta - sin(theta))
            Area expectedSegmentLength = new Area(new SquareInch(), 18 / 2 * (Math.PI / 2 - Math.Sin(Math.PI / 2))); //Pi/2 = 90 degrees, 18 = r^2
            (arcSegmentArea == expectedSegmentLength).Should().BeTrue();

            //test the central angle
            Angle centralAngle = quarterArc.CentralAngle;
            (centralAngle == Angle.RightAngle).Should().BeTrue();

            //test the center point
            Point centerPoint = quarterArc.CenterPoint;
            (centerPoint == Point.MakePointWithInches(0, 0, 4.24264)).Should().BeTrue();//sqr(3^2 + 3^2)

            //test the radius
            Distance radius = quarterArc.RadiusOfCurvature;
            (radius == new Distance(new Inch(), 4.24264)).Should().BeTrue();//sqr(3^2 + 3^2)

            //test the straight line direction (same as direction)
            Direction straightDirection = quarterArc.StraightLineDirection;
            (straightDirection == new Direction(Angle.RightAngle / 2, Angle.RightAngle / 2)).Should().BeTrue();
        }
        public void Arc_Properties_Half_Circle()
        {
            //make our default arc
            Point basePoint = Point.Origin;
            Point endPoint = Point.MakePointWithInches(0, 0, 6);
            Direction directionAtStart = new Direction(Point.MakePointWithInches(1, 1, 0));

            Arc halfArc = new Arc(basePoint, endPoint, directionAtStart);

            //test arc length
            Distance arcLength = halfArc.ArcLength;
            //s = r(theta)
            Distance expectedArclength = new Distance(new Inch(), 3 * Math.PI);
            (arcLength == expectedArclength).Should().BeTrue();

            //test arc area
            Area arcArea = halfArc.SectorArea;
            //a = (theta)/2 * r^2
            Area expectedArea = new Area(new SquareInch(), (Math.PI) *4.5 ); //Pi = 180 degrees, 9 = r^2
            (arcArea == expectedArea).Should().BeTrue();

            //test the arcSegmentArea
            Area arcSegmentArea = halfArc.SegmentArea;
            //a = r^2 / 2 * (theta - sin(theta))
            Area expectedSegmentArea = new Area(new SquareInch(), 9 * 0.5 * (Math.PI)); //Pi = 180 degrees, 9 = r^2
            (arcSegmentArea == expectedSegmentArea).Should().BeTrue();

            //test the central angle
            Angle centralAngle = halfArc.CentralAngle;
            (centralAngle == Angle.StraightAngle).Should().BeTrue();

            //test the center point
            Point centerPoint = halfArc.CenterPoint;
            (centerPoint == Point.MakePointWithInches(0, 0, 3)).Should().BeTrue();

            //test the radius
            Distance radius = halfArc.RadiusOfCurvature;
            (radius == new Distance(new Inch(), 3)).Should().BeTrue();

            //test the straight line direction (same as direction)
            Direction straightDirection = halfArc.StraightLineDirection;
            (straightDirection == new Direction(Angle.ZeroAngle, Angle.ZeroAngle)).Should().BeTrue();
        }
        public void Arc_Shift()
        {
            //make our default arc
            Point basePoint = Point.Origin;
            Point endPoint = Point.MakePointWithInches(3, 3, 4.24264);
            Direction directionAtStart = new Direction(Point.MakePointWithInches(1, 1, 0));

            Arc testArc = new Arc(basePoint, endPoint, directionAtStart);

            Shift testShift = new Shift(new Rotation(Line.ZAxis, Angle.RightAngle / 2), Point.MakePointWithInches(-3, 0.25, -2));
            Arc results = testArc.Shift(testShift);

            Arc expected = new Arc(Point.MakePointWithInches(-3, 0.25, -2), Point.MakePointWithInches(0 - 3, 4.24264 + 0.25, 4.24264 - 2), Direction.Up);

            (results == expected).Should().BeTrue();
        }
        public void Arc_Rotate()
        {
            //make our default arc
            Point basePoint = Point.Origin;
            Point endPoint = Point.MakePointWithInches(3, 3, 4.24264);
            Direction directionAtStart = new Direction(Point.MakePointWithInches(1, 1, 0));

            Arc testArc = new Arc(basePoint, endPoint, directionAtStart);

            Arc results = testArc.Rotate(new Rotation(new Line(new Direction(Point.MakePointWithInches(1, -1, 0)), Point.MakePointWithInches(0, 0, 4.24264)), Angle.RightAngle));

            Arc expected = new Arc(endPoint, Point.MakePointWithInches(0, 0, 4.24264 * 2), new Direction(Point.MakePointWithInches(0, 0, 1)));

            (results == expected).Should().BeTrue();

            //try another rotation
            Arc results2 = testArc.Rotate(new Rotation(new Line(new Direction(Point.MakePointWithInches(0, 0, 1)), Point.MakePointWithInches(1.5, 1.5, 0)), Angle.StraightAngle));

            Arc expected2 = new Arc(Point.MakePointWithInches(3, 3, 0), Point.MakePointWithInches(0, 0, 4.24264), new Direction(Point.MakePointWithInches(-1, -1, 0)));

            (results2 == expected2).Should().BeTrue();
        }
        public void Arc_Translate()
        {
            //make our default arc
            Point basePoint = Point.Origin;
            Point endPoint = Point.MakePointWithInches(-3, 2, 1);
            Direction directionAtStart = new Direction(Point.MakePointWithInches(-1, 1, 0.5));

            Arc testArc = new Arc(basePoint, endPoint, directionAtStart);

            Arc results = testArc.Translate(Point.MakePointWithInches(-1, 2, .5));

            Arc expected = new Arc(Point.MakePointWithInches(-1, 2, 0.5), Point.MakePointWithInches(-3 - 1, 2 + 2, 1 + .5), directionAtStart);

            (results == expected).Should().BeTrue();
        }
Example #8
0
 /// <summary>
 /// Creates a copy of this Arc
 /// </summary>
 /// <param name="toCopy">The Arc to copy</param>
 public Arc(Arc toCopy)
 {
     BasePoint = toCopy.BasePoint;
     EndPoint = toCopy.EndPoint;
     CenterPoint = toCopy.CenterPoint;
     NormalDirection = toCopy.NormalDirection;
 }