google / google/s2-geometry-library-java
S2polygon.getCentroid seems wrong in some case?
- Ngôn ngữ chính
- Java
- Star
- 587
- Fork
- 231
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I encountered a problem where the centroid seems wrong, i.e., the centroid is outside the polygon even when the polygon itself is a convex.
The code below plots a hexagon but the centroid seems to be way off, did I do anything wrong, thanks a lot for help?
double[] coordinates = new double[]{
47.167511,-122.1521,
47.167568,-122.151952,
47.167684,-122.151952,
47.167746,-122.1521,
47.167691,-122.152248,
47.16757,-122.152248,
47.167511,-122.1521,
};
List s2Points = new ArrayList<>();
for (int i = 0; i < coordinates.length /2; i++) {
double lat = coordinates[2 * i];
double lng = coordinates[2 * i + 1];
System.out.println(lat + "," + lng + ",");
S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lng);
s2Points.add(s2LatLng.toPoint());
}
S2Loop s2Loop = new S2Loop(s2Points);
s2Loop.normalize();
S2Polygon s2Polygon = new S2Polygon(s2Loop);
S2Point s2PolygonCentroid = s2Polygon.getCentroid();
System.out.println("Center: " + s2PolygonCentroid.toDegreesString() + " in_polygon " + s2Polygon
.contains(s2PolygonCentroid));
Output:
Center: (47.167557150782145, -122.15163675765044) in_polygon false
Kml file:
layer
<LineStyle>
<color>ff000000</color>
<width>1.2000000476837158</width>
</LineStyle>
<PolyStyle>
<color>4d000000</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
<BalloonStyle>
<text><![CDATA[<h3>$[name]</h3>]]></text>
</BalloonStyle>
<LineStyle>
<color>ff000000</color>
<width>1.7999999523162842</width>
</LineStyle>
<PolyStyle>
<color>4d000000</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
<BalloonStyle>
<text><![CDATA[<h3>$[name]</h3>]]></text>
</BalloonStyle>
normal
#style-polygon-normal
highlight
#style-polygon-highlight
<LineStyle>
<color>ff000000</color>
<width>1.2000000476837158</width>
</LineStyle>
<PolyStyle>
<color>4d000000</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
<BalloonStyle>
<text><![CDATA[<h3>$[name]</h3>]]></text>
</BalloonStyle>
<LineStyle>
<color>ff000000</color>
<width>1.7999999523162842</width>
</LineStyle>
<PolyStyle>
<color>4d000000</color>
<fill>1</fill>
<outline>1</outline>
</PolyStyle>
<BalloonStyle>
<text><![CDATA[<h3>$[name]</h3>]]></text>
</BalloonStyle>
normal
#style-s2cell-normal
highlight
#style-s2cell-highlight
test
test
#style-polygon
-122.15210000000002,47.167511 -122.151952,47.16756800000001 -122.15195200000002,47.16768400000001 -122.15210000000002,47.167746 -122.15224799999999,47.167691000000005 -122.15224799999999,47.16757 -122.15210000000002,47.167511
-122.15163675765044,47.167557150782145

Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với bản tái hiện S2Loop/S2Polygon được cung cấp và lời gọi S2Polygon.getCentroid, sau đó xác minh cách các giá trị vĩ độ/kinh độ trở thành các thể hiện S2Point. So sánh điểm được trả về với các tọa độ của polygon và kết quả contains; hoàn tất nghĩa là xác định liệu phép tính trọng tâm hay cách diễn giải đầu vào gây ra điểm được báo cáo là nằm bên ngoài, đồng thời bao phủ trường hợp đó bằng một bài kiểm thử hồi quy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- computer-graphics
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100