Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Quadrilateral" /> class.
 /// </summary>
 /// <param name="point1">The point1.</param>
 /// <param name="point2">The point2.</param>
 /// <param name="point3">The point3.</param>
 /// <param name="point4">The point4.</param>
 public Quadrilateral(
     CartesianCoordinate point1,
     CartesianCoordinate point2,
     CartesianCoordinate point3,
     CartesianCoordinate point4) : base(new List <CartesianCoordinate>() { point1, point2, point3, point4 })
 {
 }
Esempio n. 2
0
 public RoverBase(string name, CardinalDirections cardinalDirection = CardinalDirections.N, int speed = 1)
 {
     Name = name;
     CardinalDirection = cardinalDirection;
     Speed             = speed;
     Position          = new CartesianCoordinate();
 }
        public static void Initialization_with_Segments_Array_Results_in_Object_with_Immutable_Segments_Properties_List()
        {
            int    index = 1;
            double xOld  = 1;
            double yOld  = 2;

            CartesianCoordinate[] coordinates = new CartesianCoordinate[4];
            coordinates[0] = new CartesianCoordinate(0, 0);
            coordinates[1] = new CartesianCoordinate(xOld, yOld);
            coordinates[2] = new CartesianCoordinate(3, 4);
            coordinates[3] = new CartesianCoordinate(5, 6);

            LineSegment[] segments = new LineSegment[3];
            segments[0] = new LineSegment(coordinates[0], coordinates[1]);
            segments[1] = new LineSegment(coordinates[1], coordinates[2]);
            segments[2] = new LineSegment(coordinates[2], coordinates[3]);

            SegmentsBoundary boundary = new SegmentsBoundary(segments);

            Assert.IsTrue(boundary.IsReadOnly);
            Assert.AreEqual(3, boundary.Count);
            Assert.AreEqual(xOld, boundary[index].I.X);
            Assert.AreEqual(yOld, boundary[index].I.Y);

            // Alter existing coordinates to passed in reference to prove immutable
            double xNew = 7;
            double yNew = 8;

            segments[1] = new LineSegment(new CartesianCoordinate(xNew, yNew), new CartesianCoordinate(xNew + 5, yNew + 1));
            Assert.AreEqual(3, boundary.Count);
            Assert.AreEqual(xOld, boundary[index].I.X);
            Assert.AreEqual(yOld, boundary[index].I.Y);
            Assert.AreNotEqual(xNew, boundary[index].I.X);
            Assert.AreNotEqual(yNew, boundary[index].I.Y);
        }
        /// <summary>
        /// Lineary interpolates across a 2D plane to return an interpolated third dimensional value.
        /// Expected to be used for table interpolation, where x-axis are the columns, and y-axis are the rows.
        /// </summary>
        /// <param name="Po">The point in the plane to get the corresponding magnitude of.</param>
        /// <param name="ii">Point ii (closest to the origin), where <see paramref="iiValue" /> is the corresponding value.</param>
        /// <param name="jj">Point jj (farthest from the origin), where <see paramref="jjValue" /> property is the corresponding value.</param>
        /// <param name="iiValue">The value at point ii, which is closest to the origin.</param>
        /// <param name="ijValue">The value at point ij, which is in line with point ii but farthest along the x-axis (columns).</param>
        /// <param name="jiValue">The value at point ji, which is in line with point ii but farthest along the y-axis (rows).</param>
        /// <param name="jjValue">The value at point jj, which is farthest from the origin.</param>
        /// <param name="tolerance">The tolerance used for determining if a weight lies within the boundaries of the values being interpolated.</param>
        /// <returns>System.Double.</returns>
        /// <exception cref="ArgumentException">Different columns must be chosen: Column ii = Column jj = {ii.X}</exception>
        /// <exception cref="ArgumentException">Different rows must be chosen: Row ii = Row jj = {ii.Y}</exception>
        /// <exception cref="ArgumentOutOfRangeException">Point ({Po.X}, {Po.Y}) must lie within the bounds of values to interpolate within, ({ii.X}, {ii.Y}), ({jj.X}, {jj.Y})</exception>
        /// <exception cref="ArgumentException">Different columns must be chosen: Column ii = Column jj = {ii.X}</exception>
        public static double InterpolationLinear2D(
            CartesianCoordinate Po,
            CartesianCoordinate ii,
            CartesianCoordinate jj,
            double iiValue,
            double ijValue,
            double jiValue,
            double jjValue,
            double tolerance = Numbers.ZeroTolerance)
        {
            double toleranceActual = Generics.GetTolerance(Po, Generics.GetTolerance(ii, jj, tolerance));

            if (ii.X.IsEqualTo(jj.X, toleranceActual))
            {
                throw new ArgumentException($"Different columns must be chosen: Column ii = Column jj = {ii.X}");
            }
            if (ii.Y.IsEqualTo(jj.Y, toleranceActual))
            {
                throw new ArgumentException($"Different rows must be chosen: Row ii = Row jj = {ii.Y}");
            }
            if (!Po.X.IsWithinInclusive(ii.X, jj.X, tolerance) || !Po.Y.IsWithinInclusive(ii.Y, jj.Y, tolerance))
            {
                throw new ArgumentOutOfRangeException($"Point ({Po.X}, {Po.Y}) must lie within the bounds of values to interpolate within, ({ii.X}, {ii.Y}), ({jj.X}, {jj.Y})");
            }

            double Wii = (Po.X - ii.X) * (Po.Y - ii.Y);
            double Wij = (jj.X - Po.X) * (Po.Y - ii.Y);
            double Wji = (Po.X - ii.X) * (jj.Y - Po.Y);
            double Wjj = (jj.X - Po.X) * (jj.Y - Po.Y);
            double Ao  = (jj.X - ii.X) * (jj.Y - ii.Y);

            return((iiValue * Wjj + ijValue * Wji + jiValue * Wij + jjValue * Wii) / Ao);
        }
Esempio n. 5
0
        public static void CopyTo_Copies_Coordinates_to_Array()
        {
            List <CartesianCoordinate> coordinates = new List <CartesianCoordinate>()
            {
                new CartesianCoordinate(0, 0),
                new CartesianCoordinate(1, 2),
                new CartesianCoordinate(3, 4),
                new CartesianCoordinate(5, 6)
            };

            PointBoundary boundary = new PointBoundary(coordinates);

            Assert.AreEqual(4, boundary.Count);
            Assert.AreEqual(1, boundary[1].X);
            Assert.AreEqual(2, boundary[1].Y);

            CartesianCoordinate[] newCoordinates = new CartesianCoordinate[5];
            newCoordinates[0] = new CartesianCoordinate(7, 8);

            boundary.CopyTo(newCoordinates, 1);
            Assert.AreEqual(5, newCoordinates.Length);
            Assert.AreEqual(7, newCoordinates[0].X);
            Assert.AreEqual(8, newCoordinates[0].Y);
            Assert.AreEqual(0, newCoordinates[1].X);
            Assert.AreEqual(0, newCoordinates[1].Y);
            Assert.AreEqual(5, newCoordinates[4].X);
            Assert.AreEqual(6, newCoordinates[4].Y);
        }
Esempio n. 6
0
        public static bool PointIsLeftOfSegmentIntersection_Outside_Segment(double xPtN, double xIntersection)
        {
            CartesianCoordinate vertexI = new CartesianCoordinate(-1, 1);
            CartesianCoordinate vertexJ = new CartesianCoordinate(1, 2);

            return(LineToLineIntersection.PointIsLeftOfSegmentIntersection(xPtN, xIntersection, vertexI, vertexJ));
        }
Esempio n. 7
0
        [TestCase(2.1, ExpectedResult = 2)] // Top of segment
        public static double IntersectionPointY_Horizontal(double xPtN)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(2, 2);
            CartesianCoordinate ptJ = new CartesianCoordinate(3, 2);

            return(LineToLineIntersection.IntersectionPointY(xPtN, ptI, ptJ));
        }
 /// <summary>
 /// Calculate the component-wise product.
 /// </summary>
 /// <param name="point1">The point1.</param>
 /// <param name="point2">The point2.</param>
 /// <returns>The result of component-wise multiplication.</returns>
 public static CartesianCoordinate ComponentProduct(this CartesianCoordinate point1, CartesianCoordinate point2)
 {
     return(new CartesianCoordinate(
                point1.X * point2.X,
                point1.Y * point2.Y,
                point1.Z * point2.Z));
 }
 /// <summary>
 /// Calculates the vector product.
 /// </summary>
 /// <param name="point1">The point1.</param>
 /// <param name="point2">The point2.</param>
 /// <returns>The result of vector product operation.</returns>
 public static CartesianCoordinate VectorProduct(this CartesianCoordinate point1, CartesianCoordinate point2)
 {
     return(new CartesianCoordinate(
                point1.Y * point2.Z - point1.Z * point2.Y,
                point1.Z * point2.X - point1.X * point2.Z,
                point1.X * point2.Y - point1.Y * point2.X));
 }
        private BaseDyadCoordinate <Complex, ComplexCalculator> setDiagonalElements(
            DispersionParameter dispersion,
            double radius,
            CartesianCoordinate exyz)
        {
            double medRef = dispersion.MediumRefractiveIndex * dispersion.MediumRefractiveIndex;//this is correct

            Complex eps = this.mediumManager.GetEpsilon(dispersion, radius);

            // Complex value inverted to Clausius-Mossotti polarization.
            Complex clausiusMosottiPolar = (eps - 1.0 * medRef) / (eps + 2.0 * medRef);
            Complex multiplier           = Complex.Reciprocal(clausiusMosottiPolar);

            double volumeFactorInverted = 1 / (radius * radius * radius);
            var    complex =
                new DyadCoordinate <Complex, ComplexCalculator>(multiplier * volumeFactorInverted);

            double kmod      = dispersion.WaveVector.Norm;
            double radiation = 2.0 / 3.0 * kmod * kmod * kmod; // доданок, що відповідає за релаксаційне випромінювання.

            var radiativeReaction =
                new DyadCoordinate <Complex, ComplexCalculator>(Complex.ImaginaryOne * radiation);

            BaseDyadCoordinate <Complex, ComplexCalculator> surfaceInteraction = SurfaceInteractionCoeff(dispersion, exyz);

            return(complex - radiativeReaction + surfaceInteraction);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RightTriangle" /> class.
 /// </summary>
 /// <param name="apexCoordinate">The apex coordinate.</param>
 public RightTriangle(CartesianCoordinate apexCoordinate)
 {
     _sideLengthA = apexCoordinate.X;
     _sideLengthB = apexCoordinate.Y;
     SetCoordinates(LocalCoordinates());
     setCenterCoordinates();
 }
        private BaseDyadCoordinate <Complex, ComplexCalculator> setNonDiagonalElements(
            DispersionParameter dispersion,
            CartesianCoordinate displacement)
        {
            double rmod  = displacement.Norm;
            double rmod2 = rmod * rmod;
            double rmod3 = rmod2 * rmod;

            double kmod = dispersion.WaveVector.Norm;
            double kr   = kmod * rmod;

            BaseDyadCoordinate <Complex, ComplexCalculator> dyadProduct =
                CoordinateExtensions.DyadProduct(ref displacement, ref displacement);

            var initDyad =
                new DiagonalDyadCoordinate <Complex, ComplexCalculator>(rmod2);

            BaseDyadCoordinate <Complex, ComplexCalculator> firstMember = (kmod * kmod) * (dyadProduct - initDyad);


            BaseDyadCoordinate <Complex, ComplexCalculator> secondMember = (1 / rmod2) * (Complex.ImaginaryOne * kr - 1) *
                                                                           (3 * dyadProduct - initDyad);

            Complex multiplier = Complex.FromPolarCoordinates(1 / rmod3, kr);

            return(multiplier * (firstMember + secondMember));
        }
        /// <summary>
        /// Sets the orthocenter.
        /// </summary>
        protected void setOrthocenter()
        {
            // If any angle is 90 degrees, the orthocenter lies at the vertex at that angle
            double angleA = getAngleA();

            if (angleA.IsEqualTo(Num.PiOver2, 10E-10))
            {
                OrthoCenter = PointA;
                return;
            }

            double angleB = getAngleB();

            if (angleB.IsEqualTo(Num.PiOver2, 10E-10))
            {
                OrthoCenter = PointB;
                return;
            }

            double angleC = getAngleC();

            if (angleC.IsEqualTo(Num.PiOver2, 10E-10))
            {
                OrthoCenter = PointC;
                return;
            }

            double denominator = Trig.Tan(angleA) + Trig.Tan(angleB) + Trig.Tan(angleC);

            OrthoCenter = new CartesianCoordinate(
                (PointA.X * Trig.Tan(angleA) + PointB.X * Trig.Tan(angleB) + PointC.X * Trig.Tan(angleC)) / denominator,
                (PointA.Y * Trig.Tan(angleA) + PointB.Y * Trig.Tan(angleB) + PointC.Y * Trig.Tan(angleC)) / denominator
                );
        }
        /// <summary>
        /// Sets the in-center.
        /// </summary>
        protected void setInCenter()
        {
            double x_ic = (SideLengthA() * PointA.X + SideLengthB() * PointB.X + SideLengthC() * PointC.X) / Perimeter();
            double y_ic = (SideLengthA() * PointA.Y + SideLengthB() * PointB.Y + SideLengthC() * PointC.Y) / Perimeter();

            InCenter = new CartesianCoordinate(x_ic, y_ic);
        }
Esempio n. 15
0
        public static bool PointIsBelowLineBottomExclusive_On_Ends(double yPtN)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(1, 2);
            CartesianCoordinate ptJ = new CartesianCoordinate(15, 5);

            return(LineToLineIntersection.PointIsBelowLineBottomExclusive(yPtN, ptI, ptJ));
        }
Esempio n. 16
0
        public static bool PointIsWithinLineHeight_SlopedLine(double yPtN, double yLeftEnd, double yRightEnd)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(1, yLeftEnd);
            CartesianCoordinate ptJ = new CartesianCoordinate(15, yRightEnd);

            return(LineToLineIntersection.PointIsWithinLineHeightInclusive(yPtN, ptI, ptJ));
        }
Esempio n. 17
0
        [TestCase(2.1, ExpectedResult = 2)] // Right of segment
        public static double IntersectionPointX_Vertical(double yPtN)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(2, 2);
            CartesianCoordinate ptJ = new CartesianCoordinate(2, 3);

            return(LineToLineIntersection.IntersectionPointX(yPtN, ptI, ptJ));
        }
Esempio n. 18
0
        public static bool PointIsWithinLineHeightInclusive_On_Ends(double yPtN)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(1, 2);
            CartesianCoordinate ptJ = new CartesianCoordinate(15, 5);

            return(LineToLineIntersection.PointIsWithinLineHeightInclusive(yPtN, ptI, ptJ));
        }
Esempio n. 19
0
        public static void IntersectionPointY_Vertical_Throws_Argument_Exception()
        {
            CartesianCoordinate ptI = new CartesianCoordinate(2, 2);
            CartesianCoordinate ptJ = new CartesianCoordinate(2, 4);

            Assert.Throws <ArgumentException>(() => LineToLineIntersection.IntersectionPointY(2, ptI, ptJ));
        }
Esempio n. 20
0
        public static bool PointIsWithinLineWidth_Sloped(double xPtN, double xLeftEnd, double xRightEnd)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(xLeftEnd, 1);
            CartesianCoordinate ptJ = new CartesianCoordinate(xRightEnd, 15);

            return(LineToLineIntersection.PointIsWithinLineWidthInclusive(xPtN, ptI, ptJ));
        }
Esempio n. 21
0
        public static bool PointIsBelowSegmentIntersection_Outside_Segment(double yPtN, double yIntersection)
        {
            CartesianCoordinate vertexI = new CartesianCoordinate(1, -1);
            CartesianCoordinate vertexJ = new CartesianCoordinate(2, 1);

            return(LineToLineIntersection.PointIsBelowSegmentIntersection(yPtN, yIntersection, vertexI, vertexJ));
        }
Esempio n. 22
0
        public static bool PointIsWithinLineWidth_On_Ends_with_Ends_Excluded(double xPtN)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(1, 2);
            CartesianCoordinate ptJ = new CartesianCoordinate(15, 5);

            return(LineToLineIntersection.PointIsWithinLineWidthExclusive(xPtN, ptI, ptJ));
        }
Esempio n. 23
0
        public static void Initialization_with_Coordinates_Array_Results_in_Object_with_Immutable_Coordinates_Properties_List()
        {
            int    index = 1;
            double xOld  = 1;
            double yOld  = 2;

            CartesianCoordinate[] coordinates = new CartesianCoordinate[4];
            coordinates[0] = new CartesianCoordinate(0, 0);
            coordinates[1] = new CartesianCoordinate(xOld, yOld);
            coordinates[2] = new CartesianCoordinate(3, 4);
            coordinates[3] = new CartesianCoordinate(5, 6);

            double xNew = 7;
            double yNew = 8;

            PointBoundary boundary = new PointBoundary(coordinates);

            Assert.AreEqual(GeometryLibrary.ZeroTolerance, boundary.Tolerance);
            Assert.IsTrue(boundary.IsReadOnly);
            Assert.AreEqual(4, boundary.Count);
            Assert.AreEqual(xOld, boundary[index].X);
            Assert.AreEqual(yOld, boundary[index].Y);

            // Alter existing coordinates to passed in reference to prove immutable
            coordinates[1] = new CartesianCoordinate(xNew, yNew);
            Assert.AreEqual(4, boundary.Count);
            Assert.AreEqual(xOld, boundary[index].X);
            Assert.AreEqual(yOld, boundary[index].Y);
            Assert.AreNotEqual(xNew, boundary[index].X);
            Assert.AreNotEqual(yNew, boundary[index].Y);
        }
Esempio n. 24
0
        public static bool PointIsLeftOfLineEnd_SlopedLine(double xPtN, double xLeftEnd, double xRightEnd)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(xLeftEnd, 10);
            CartesianCoordinate ptJ = new CartesianCoordinate(xRightEnd, 20);

            return(LineToLineIntersection.PointIsLeftOfLineEndInclusive(xPtN, ptI, ptJ));
        }
        /// <summary>
        /// Returns the pair of segments that join at the provided coordinate.
        /// If the point is the first or last point, the leading or following segment will be null.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>Tuple&lt;IPathSegment, IPathSegment&gt;.</returns>
        public Tuple <IPathSegment, IPathSegment> AdjacentSegments(CartesianCoordinate point)
        {
            if (!PointBoundary().Contains(point))
            {
                return(new Tuple <IPathSegment, IPathSegment>(null, null));
            }

            IPathSegment itemI = null;
            IPathSegment itemJ = null;

            foreach (IPathSegment segment in this)
            {
                if (segment.I == point)
                {
                    itemJ = segment;
                    continue;
                }
                if (segment.J == point)
                {
                    itemI = segment;
                    continue;
                }
                if (itemI != null && itemJ != null)
                {
                    break;
                }
            }
            return(new Tuple <IPathSegment, IPathSegment>(itemI, itemJ));
        }
Esempio n. 26
0
        public static bool PointIsLeftOfLineEndExclusive_On_Ends(double xPtN)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(1, 2);
            CartesianCoordinate ptJ = new CartesianCoordinate(15, 5);

            return(LineToLineIntersection.PointIsLeftOfLineEndExclusive(xPtN, ptI, ptJ));
        }
        public static void Changing_Tolerance_Cascades_to_Properties()
        {
            double defaultTolerance = 10E-6;

            CartesianCoordinate[] coordinates = new CartesianCoordinate[4];
            coordinates[0] = new CartesianCoordinate(0, 0);
            coordinates[1] = new CartesianCoordinate(1, 2);
            coordinates[2] = new CartesianCoordinate(3, 4);
            coordinates[3] = new CartesianCoordinate(5, 6);

            LineSegment[] segments = new LineSegment[3];
            segments[0] = new LineSegment(coordinates[0], coordinates[1]);
            segments[1] = new LineSegment(coordinates[1], coordinates[2]);
            segments[2] = new LineSegment(coordinates[2], coordinates[3]);

            SegmentsBoundary boundary = new SegmentsBoundary(segments);

            Assert.AreEqual(defaultTolerance, boundary.Tolerance);
            Assert.AreEqual(defaultTolerance, boundary[0].Tolerance);
            Assert.AreEqual(defaultTolerance, boundary[1].Tolerance);
            Assert.AreEqual(defaultTolerance, boundary[2].Tolerance);

            double newTolerance = 10E-3;

            boundary.Tolerance = newTolerance;

            Assert.AreEqual(newTolerance, boundary.Tolerance);
            Assert.AreEqual(newTolerance, boundary[0].Tolerance);
            Assert.AreEqual(newTolerance, boundary[1].Tolerance);
            Assert.AreEqual(newTolerance, boundary[2].Tolerance);
        }
Esempio n. 28
0
        public static bool PointIsBelowLineBottom_SlopedLine(double yPtN, double yBottomEnd, double yTopEnd)
        {
            CartesianCoordinate ptI = new CartesianCoordinate(10, yBottomEnd);
            CartesianCoordinate ptJ = new CartesianCoordinate(20, yTopEnd);

            return(LineToLineIntersection.PointIsBelowLineBottomInclusive(yPtN, ptI, ptJ));
        }
Esempio n. 29
0
        private static List <Voxel> transformVerticesToVoxels(LoadResult result)
        {
            var    listVoxels = new List <CartesianCoordinate>();
            double resolution = 0;

            foreach (var group in result.Groups)
            {
                var faces = @group.Faces.Where(x => x.All(y => y.NormalIndex == 1));

                foreach (var face in faces)
                {
                    var x = face.Min(i => result.Vertices[i.VertexIndex - 1].X);
                    var y = face.Min(i => result.Vertices[i.VertexIndex - 1].Y);
                    var z = face.Min(i => result.Vertices[i.VertexIndex - 1].Z);

                    listVoxels.Add(new CartesianCoordinate(x, y, z));

                    if (resolution <= double.Epsilon)
                    {
                        var sibling1 = result.Vertices[face[0].VertexIndex - 1];
                        var sibling2 = result.Vertices[face[1].VertexIndex - 1];

                        resolution = Math.Max(
                            Math.Max(Math.Abs(sibling1.X - sibling2.X), Math.Abs(sibling1.Y - sibling2.Y)),
                            Math.Abs(sibling1.Z - sibling2.Z));
                    }
                }
            }

            var min = new CartesianCoordinate(listVoxels.Min(x => x.X), listVoxels.Min(x => x.Y), listVoxels.Min(x => x.Z));

            var transform = listVoxels.Select(x => new Voxel((x - min) / resolution)).ToList();

            return(transform);
        }
Esempio n. 30
0
 public Cuboid(double length, double height, double width, CartesianCoordinate center = null, Orientation orientation = null)
     : base(center, orientation)
 {
     this.length = length;
     this.height = height;
     this.width  = width;
 }