4

How to check that a polygon inside google map is "valid", I mean as follows:

Valid:

Valid

Not valid:

enter image description here

PolygonOptions po = new PolygonOptions()
                            .strokeColor(Color.RED)
                            .fillColor(Color.BLUE).strokeWidth(3);

                    for(int i=0;i<listLatLng.size();i++){
                        googleMap.addMarker(new MarkerOptions().position(listLatLng.get(i)));
                        po.add(listLatLng.get(i));
                    }

                    googleMap.addPolygon(po);

Thank you in advance.

zamroni hamim
  • 545
  • 1
  • 6
  • 21
  • Conceptually, both are valid. I think you are talking about Regular and irregular (Convex and non-Convex )shapes of polygons – Zaid Mirza Jul 23 '18 at 05:03
  • https://stackoverflow.com/questions/471962/how-do-i-efficiently-determine-if-a-polygon-is-convex-non-convex-or-complex check this. – Zaid Mirza Jul 23 '18 at 05:06
  • looking at shis: https://en.wikipedia.org/wiki/Concave_polygon, I don't think it's about "convex/non convex", since in that link, the shape of the sample image will still able to produce the "blue" area despite being non convex. So, what I want to know is how to differ it with the "not valid" or the shape that cannot produce the blue area above, in android. – zamroni hamim Jul 23 '18 at 07:13
  • 1
    @ZaidMirza 's link correctly suggests the 'Not Valid' case as representative of a complex polygon. The test for such a case is to test each polyline segment for intersection with all other member polylines. Here's a discussion of the cross-product test for intersection: https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect/565282#565282 ; and an apparent android-java implementation: https://stackoverflow.com/questions/49535476/how-to-find-intersect-between-two-polylines-in-android –  Jul 25 '18 at 01:51

0 Answers0