예제 #1
0
        private List <CartesianCoordinates> GetDifferences()
        {
            var planetCoordinates = planetList.Select(p => p.PolarPosition.ToCartesian()).ToList();

            CartesianCoordinates coord = planetCoordinates[0];
            var diffList = new List <CartesianCoordinates>();

            for (int i = 1; i < planetCoordinates.Count; i++)
            {
                diffList.Add(planetCoordinates[i] - coord);
                coord = planetCoordinates[i];
            }

            return(diffList);
        }
예제 #2
0
        public static bool IsPointInsideTriangle(CartesianCoordinates point, List <CartesianCoordinates> triangle)
        {
            if (triangle.Count != 3)
            {
                throw new ArgumentException("Triangle should have 3 points");
            }

            var bigArea = AreaOfTriangle(triangle[0], triangle[1], triangle[2]);

            var a1 = AreaOfTriangle(point, triangle[0], triangle[1]);
            var a2 = AreaOfTriangle(point, triangle[0], triangle[2]);
            var a3 = AreaOfTriangle(point, triangle[1], triangle[2]);

            return(DoubleEquals(bigArea, (a1 + a2 + a3)));
        }
예제 #3
0
 public bool Equals(CartesianCoordinates other, int precision)
 {
     return(X.EqualsPrecision(other.X, Config.Precision) && Y.EqualsPrecision(other.Y, precision));
 }
예제 #4
0
 public static double AreaOfTriangle(CartesianCoordinates p1, CartesianCoordinates p2, CartesianCoordinates p3)
 {
     return(Math.Abs((p1.X * (p2.Y - p3.Y) +
                      p2.X * (p3.Y - p1.Y) +
                      p3.X * (p1.Y - p2.Y)) / 2d));
 }
예제 #5
0
 public static bool LineFromTwoPointPassesOrigin(CartesianCoordinates p1, CartesianCoordinates p2)
 {
     return(DoubleEquals(p1.X * (p2.Y - p1.Y), p1.Y * (p2.X - p1.X)));
 }