diff --git a/opdracht2/GeoJsonParser.cs b/opdracht2/GeoJsonParser.cs index be782d6..bc5bf03 100644 --- a/opdracht2/GeoJsonParser.cs +++ b/opdracht2/GeoJsonParser.cs @@ -47,7 +47,7 @@ namespace opdracht2 { try { - List EnkelePolygonLijst = maakPolygonLijn(maakPolygonLijst(JsonConvert.DeserializeObject(v["geometry"].ToString()))); + List EnkelePolygonLijst = MaakPolygonLijn(MaakPolygonLijst(JsonConvert.DeserializeObject(v["geometry"].ToString()))); returnWaarde.AddRange(maakDriehoeken(EnkelePolygonLijst)); } catch (Exception e) @@ -96,14 +96,14 @@ namespace opdracht2 if (polygonLijst.Count == 3) { - returnWaarde.Add(createNewPolygon(polygonLijst[punt1Index], polygonLijst[punt2Index], + returnWaarde.Add(CreateNewPolygon(polygonLijst[punt1Index], polygonLijst[punt2Index], polygonLijst[punt3Index])); break; } - double hoek = getAngle(polygonLijst[punt1Index], polygonLijst[punt2Index], polygonLijst[punt3Index]); + double hoek = GetAngle(polygonLijst[punt1Index], polygonLijst[punt2Index], polygonLijst[punt3Index]); if (hoek < 180) { - returnWaarde.Add(createNewPolygon(polygonLijst[punt1Index], polygonLijst[punt2Index], + returnWaarde.Add(CreateNewPolygon(polygonLijst[punt1Index], polygonLijst[punt2Index], polygonLijst[punt3Index])); polygonLijst.RemoveAt(punt2Index); @@ -119,14 +119,14 @@ namespace opdracht2 } //https://stackoverflow.com/a/31334882 - private static double getAngle(Point p1, Point p2, Point p3) + private static double GetAngle(Point p1, Point p2, Point p3) { return Math.Atan2(p3.Y - p1.Y, p3.X - p1.X) - Math.Atan2(p2.Y - p1.Y, p2.X - p1.X); } - private static System.Windows.Shapes.Polygon createNewPolygon(Point punt1, Point punt2, Point punt3) + private static System.Windows.Shapes.Polygon CreateNewPolygon(Point punt1, Point punt2, Point punt3) { System.Windows.Shapes.Polygon returnWaarde = new System.Windows.Shapes.Polygon(); PointCollection puntCollectie = new PointCollection(); @@ -149,7 +149,7 @@ namespace opdracht2 return returnWaarde; } - private static List> maakPolygonLijst(MultiPolygon multiPolygon) + private static List> MaakPolygonLijst(MultiPolygon multiPolygon) { List> polygonAlsPuntenLijst = new List>(); foreach (GeoJSON.Net.Geometry.Polygon geojsonPolygon in multiPolygon.Coordinates) @@ -197,7 +197,7 @@ namespace opdracht2 return polygonAlsPuntenLijst; } - private static List maakPolygonLijn(List> multiPolygon) + private static List MaakPolygonLijn(List> multiPolygon) { //zoek dichtsbijzijnde punt wanneer toevoegen volgende vector en voeg pas vanaf dat punt toe. bool richting = true; //richting van inlezen polygon (met klok mee, tegen in klok) @@ -214,6 +214,7 @@ namespace opdracht2 { Point dichtsbijzijndePunt = returnWaarde[0]; Point dichtsbijzijndeNieuwePunt = normalizedPoly[0]; + foreach (Point punt in returnWaarde) { //ik dacht dat dit beter ging zijn, maar blijkbaar geen echt effect, behalve shit vertragen. @@ -227,14 +228,9 @@ namespace opdracht2 dichtsbijzijndeNieuwePunt = punt2; } } - - /*if (Vector2.Distance(punt, normalizedPoly[0]) < Vector2.Distance(dichtsbijzijndePunt, normalizedPoly[0])) - { - dichtsbijzijndePunt = punt; - }*/ } - //normalizedPoly = orderList(normalizedPoly, dichtsbijzijndeNieuwePunt); + normalizedPoly = orderList(normalizedPoly, dichtsbijzijndeNieuwePunt); returnWaarde.InsertRange(returnWaarde.IndexOf(dichtsbijzijndePunt), normalizedPoly); } else @@ -247,12 +243,12 @@ namespace opdracht2 return returnWaarde; } - - private static List orderList(List normalizedPoly, Vector2 dichtsbijzijndeNieuwePunt) + + private static List orderList(List normalizedPoly, Point dichtsbijzijndeNieuwePunt) { int i = normalizedPoly.IndexOf(dichtsbijzijndeNieuwePunt); int check = i; - List returnWaarde = new List(); + List returnWaarde = new List(); do { if (i >= normalizedPoly.Count) i -= normalizedPoly.Count; @@ -303,10 +299,6 @@ namespace opdracht2 index = i; dmax = distance; } - else - { - Debug.WriteLine("distance between points = " + distance); - } } @@ -336,52 +328,5 @@ namespace opdracht2 } - public static Double PerpendicularDistance - (Vector2 Point1, Vector2 Point2, Vector2 Point) - { - //Area = |(1/2)(x1y2 + x2y3 + x3y1 - x2y1 - x3y2 - x1y3)| *Area of triangle - //Base = v((x1-x2)²+(x1-x2)²) *Base of Triangle* - //Area = .5*Base*H *Solve for height - //Height = Area/.5/Base - - Double area = Math.Abs(.5 * (Point1.X * Point2.Y + Point2.X * - Point.Y + Point.X * Point1.Y - Point2.X * Point1.Y - Point.X * - Point2.Y - Point1.X * Point.Y)); - Double bottom = Math.Sqrt(Math.Pow(Point1.X - Point2.X, 2) + - Math.Pow(Point1.Y - Point2.Y, 2)); - Double height = area / bottom * 2; - - return height; - - //Another option - //Double A = Point.X - Point1.X; - //Double B = Point.Y - Point1.Y; - //Double C = Point2.X - Point1.X; - //Double D = Point2.Y - Point1.Y; - - //Double dot = A * C + B * D; - //Double len_sq = C * C + D * D; - //Double param = dot / len_sq; - - //Double xx, yy; - - //if (param < 0) - //{ - // xx = Point1.X; - // yy = Point1.Y; - //} - //else if (param > 1) - //{ - // xx = Point2.X; - // yy = Point2.Y; - //} - //else - //{ - // xx = Point1.X + param * C; - // yy = Point1.Y + param * D; - //} - - //Double d = DistanceBetweenOn2DPlane(Point, new Point(xx, yy)); - } } } \ No newline at end of file diff --git a/opdracht2/MainWindow.xaml.cs b/opdracht2/MainWindow.xaml.cs index ffea5da..87680a5 100644 --- a/opdracht2/MainWindow.xaml.cs +++ b/opdracht2/MainWindow.xaml.cs @@ -93,30 +93,8 @@ namespace opdracht2 buffer.Add(f[0]); f.RemoveAt(0); } - //List f = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), c.Width, c.Height); - - /* - foreach (Polygon p in f) - { - foreach(Point po in p.Points) - { - //fuck c# https://stackoverflow.com/a/36482552 - Ellipse dot = new Ellipse(); - dot.Stroke = Brushes.Black; - dot.StrokeThickness = 1; - Canvas.SetZIndex(dot, 3); - dot.Height = 5; - dot.Width = 5; - dot.Fill = new SolidColorBrush(Colors.Black); - dot.Margin = new Thickness(po.X, po.Y, 0, 0); - c.Children.Add(dot); - } - c.Children.Add(p); - } - */ - - - } + } } +} diff --git a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll index a779770..ae5fed2 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll and b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll differ diff --git a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb index e221896..3b4ccba 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb and b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/MainWindow.baml b/opdracht2/obj/Debug/netcoreapp3.1/MainWindow.baml deleted file mode 100644 index f023a44..0000000 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/MainWindow.baml and /dev/null differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll index a779770..ae5fed2 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources index 99add43..fb94220 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb index e221896..3b4ccba 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache index be05267..4e2a083 100644 --- a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache +++ b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache @@ -10,11 +10,11 @@ none false TRACE;DEBUG;NETCOREAPP;NETCOREAPP3_1 C:\Users\Beppe\source\repos\opdracht2\opdracht2\App.xaml -11316880640 +1-1315075995 -41434824894 -195-1386093099 +41252897694 +195-1941964533 MainWindow.xaml; -False +True