Reputation: 11
How do I plot a polygon with the centroid located outside of the polygon in Python?
Upvotes: 1
Views: 282
Reputation: 3604
No idea how to in python, but I guess the assumption is, that polygon has to be convex. Not necessary. Below an illustration in R with standard st_centroid (as in Postgis or sf
).
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1; sf_use_s2() is TRUE
pl1 = list(rbind(c(0,0), c(1,0), c(0.12,0.12), c(0,1), c(0,0)))
polygon <- st_polygon(x = pl1)
plot(polygon)
pt <- st_centroid(polygon)
plot(pt, pch = 18, col = "red", add = TRUE)
Created on 2022-02-06 by the reprex package (v2.0.1)
Upvotes: 2