public void LineSegment_GetInitialDirection_ShouldReturnDirection()
        {
            LineSegment lineSegment = new LineSegment(Point.MakePointWithInches(1, 1, 1));

            Direction direction = new Direction(1, 1, 1);

            lineSegment.InitialDirection.Should().Be(direction);
        }
        private static Polygon _makeRectangle(Vector baseSegment, Distance height, Direction referencePlaneNormal)
        {
            if (referencePlaneNormal == null)
            {
                referencePlaneNormal = Direction.Out;
            }

            Direction heightDirection = referencePlaneNormal.CrossProduct(baseSegment.Direction);
            var heightVector = new Vector(heightDirection, height);
            
            Polygon polygon = Parallelogram(baseSegment, heightVector);

            return polygon;
        }
        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 Direction_ConstuctorsAndEquality()
        {
            Direction direction1 = Direction.Up;
            Direction direction2 = new Direction(new Angle(new Degree(), 33));
            Direction direction3 = Direction.Out;
            Direction direction4 = new Direction(new Angle(new Degree(), 33), Angle.RightAngle);
            Direction direction5 = null;

            direction1.Should().NotBe(direction2);
            direction1.Should().NotBe(direction3);
            direction1.Should().NotBe(direction4);

            direction2.Should().NotBe(direction3);
            (direction2 == direction4).Should().BeTrue();

            direction3.Should().NotBe(direction4);

            //now check null stuff
            (direction1 == null).Should().BeFalse();
            (direction5 == null).Should().BeTrue();
            (direction1 == direction5).Should().BeFalse();
            (direction5 == direction1).Should().BeFalse();

            (direction1 != null).Should().BeTrue();
            (direction5 != null).Should().BeFalse();
            (direction1 != direction5).Should().BeTrue();
            (direction5 != direction1).Should().BeTrue();

            Point testPoint = Point.MakePointWithInches(0.006, 0.003, -1.4999);
            Direction testErrorHandling = new Direction(testPoint);
            Direction expectedErrorDirection = Direction.Back;
            (testErrorHandling == expectedErrorDirection).Should().BeTrue();

            //now try the Z Direction too
            Point testPoint0 = Point.MakePointWithInches(0.006, 0.003, 1.4999);
            Direction testDirection1 = new Direction(testPoint0);
            Direction expected = Direction.Out;
            (testDirection1 == expected).Should().BeTrue();

            Point testPoint2 = Point.MakePointWithInches(1.0 / 32, 0.006, 1.488);
            Direction testDirection2 = new Direction(testPoint2);
            //Just barely more than a 1 degree angle between them
            (testDirection2 == expected).Should().BeFalse();
        }
        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 Point_IsOnLineWithComponentOfDirectionEqualToZeroTest()
        {
            Point testBasePoint = Point.MakePointWithInches(1, 0, 2);
            Direction testDirection = new Direction(Point.MakePointWithInches(0, 3, 1));

            Line testLine = new Line(testDirection, testBasePoint);

            Point pointOnLine = Point.MakePointWithInches(1, 6, 4);

            pointOnLine.IsOnLine(testLine).Should().BeTrue();
        }
        public void LineSegment_ConstructorPointDirectionDistance_ShouldThrowException_IfDistanceIsNull()
        {
            Direction direction = new Direction(1, 0, 0);
            Distance distance = null;

            Action construct = () => new LineSegment(Point.Origin, direction, distance);
            construct.ShouldThrow<Exception>();
        }
 public Rectangle(Vector baseSegment, Distance height, Direction referencePlaneNormal = null)
     : base(_makeRectangle(baseSegment, height, referencePlaneNormal)) { }
Example #12
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;
 }
Example #13
0
 private Arc(Point basePoint, Point endPoint, Point centerPoint, Direction normalDirection)
 {
     this.BasePoint = basePoint;
     this.EndPoint = endPoint;
     this.CenterPoint = centerPoint;
     this.NormalDirection = normalDirection;
 }
Example #14
0
 public Arc(Point basePoint, Point endPoint, Line normalLine)
 {
     if (basePoint != endPoint && !new Direction(basePoint, endPoint).IsPerpendicularTo(normalLine.Direction))
     {
         throw new GeometricException();
     }
     var projected = basePoint.ProjectOntoLine(normalLine);
     if (projected == basePoint)
     {
         throw new GeometricException();
     }
     this.BasePoint = basePoint;
     this.EndPoint = endPoint;
     this.CenterPoint = projected;
     this.NormalDirection = normalLine.Direction;            
 }
Example #15
0
        public Arc(Point basePoint, Point endPoint, Direction initialDirection)
        {
            this.BasePoint = basePoint;
            this.EndPoint = endPoint;
            if (this.IsClosed)
            {
                throw new GeometricException("Not enough information given to determine curvature.");
            }
            var segmentBetweenPoints = new LineSegment(basePoint,endPoint);
            this.NormalDirection = initialDirection.CrossProduct(segmentBetweenPoints.Direction);

            var plane1 = new Plane(BasePoint, initialDirection);
            var plane2 = new Plane(segmentBetweenPoints.MidPoint, segmentBetweenPoints.Direction);
            var intersectingLine = plane1.IntersectWithPlane(plane2);
            var containingPlane = new Plane(BasePoint, NormalDirection);
            var centerPoint = intersectingLine.IntersectWithPlane(containingPlane);
            this.CenterPoint = centerPoint;
            //var line1 = new Line(BasePoint, NormalDirection.CrossProduct(initialDirection));
            //var line2 = new Line(segmentBetweenPoints.MidPoint, NormalDirection.CrossProduct(segmentBetweenPoints.Direction));
            //this._centerPoint = line1.IntersectWithLine(line2);
        }
        public void LineSegment_ConstructorPointDirectionDistance_ShouldCreateLineSegmentFromPointDirectionAndDistance()
        {
            Direction direction = new Direction(1, 0, 0);
            Distance distance = new Distance(1, Distance.Inches);

            LineSegment lineSegment = new LineSegment(Point.Origin, direction, distance);

            lineSegment.Should().Be(new LineSegment(Point.MakePointWithInches(1, 0, 0)));
        }
        public void LineSegment_ConstructorPointDirectionDistance_ShouldCreateLineSegmentFromOrigin_IfPointIsNull()
        {
            Point point = null;
            Direction direction = new Direction(1, 0, 0);
            Distance distance = new Distance(1, Distance.Inches);

            LineSegment lineSegment = new LineSegment(point, direction, distance);

            lineSegment.Should().Be(new LineSegment(Point.MakePointWithInches(1, 0, 0)));
        }
 private static Shift GetRotation(Direction normal)
 {
     if (normal.IsParallelTo(Direction.Out))
     {
         return Rotation.Identity;
     }
     var angle = normal.AngleBetween(Direction.Out);
     var axis = new Line(normal.CrossProduct(Direction.Out));
     var rotation = new Shift(new Rotation(axis, angle));
     return rotation;
 }
        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();
        }
        public void Line_Rotate_AboutZAxis()
        {
            Point basePointLine1 = Point.MakePointWithInches(2, 1, 0);
            Point otherPointLine1 = Point.MakePointWithInches(3, 3, 3);

            Line line1 = new Line(basePointLine1, otherPointLine1);
            Line axisLine = new Line(Point.Origin, Point.MakePointWithInches(0, 0, 1));

            Angle rotationAngle = new Angle(new Degree(), 199);

            Line actualResult = line1.Rotate(new Rotation(axisLine, rotationAngle));

            Point expectedResultBasePoint = Point.MakePointWithInches(-1.5654689967414768, -1.5966548845136304, 0.0);
            Direction expectedDirection = new Direction(Point.MakePointWithInches(-0.29438226668500322,-2.2166053056557904,3.0));
            Line expectedResult = new Line(expectedDirection, expectedResultBasePoint);

            (expectedResult == actualResult).Should().BeTrue();
        }