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); }
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))); }
public bool Equals(CartesianCoordinates other, int precision) { return(X.EqualsPrecision(other.X, Config.Precision) && Y.EqualsPrecision(other.Y, precision)); }
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)); }
public static bool LineFromTwoPointPassesOrigin(CartesianCoordinates p1, CartesianCoordinates p2) { return(DoubleEquals(p1.X * (p2.Y - p1.Y), p1.Y * (p2.X - p1.X))); }