Geometric center of Prague
Kluci z Prahy, also known as Honest guide guys, published new video about exact center of Prague. As I was watching, I was quite curious about how they are going to compute the centroid of the non-convex polygon.
I was quite sad, that they didn't. They just picker most east, west, north and south points of Prague, drawn a line between them and then picked intersection it as a center. So, how can we find geometric center?
![](Geometric_center_of_Prague/kluci_mapa_thumb.jpg)
Note: geometric center is the place, where you could stick a pin if you cut the shape from the paper, and the map would be balanced and wouldn't fall off.
Get a polygon map of Prague
This is quite tricky. Fortunately, you can just google for suitable SVG. I've found this one:
I've opened it in text editor and removed everything else except the polygon itself:
Blender magic
This SVG file can be imported to Blender:
![](Geometric_center_of_Prague/svg_import_1_thumb.jpg)
Scaled up:
![](Geometric_center_of_Prague/svg_import_2_thumb.jpg)
In the middle of the screen, you can see "origin point", in the middle of the 3D cursor. Little yellow dot. Blender has this neat feature, where you can quickly move "origin point" to the center of the geometry. In 3D modeling, you use this all the time because you want to do some kind of modification (rotation and so on) relevant to the centroid (mass) of the geometry.
![](Geometric_center_of_Prague/svg_import_3_thumb.jpg)
Then it is easy to just move the object (polygon map) to the cursor and rotate it 180° because for some reason it is upside-down:
![](Geometric_center_of_Prague/svg_import_4_thumb.jpg)
Now it would be nice to fit it to some visual map, to get the point. I've used a map from the official Prague website. Then I've rotated and scaled the map polygon until it matched the contours in the picture map.
Rotation is required because SVG data points I've used are for some reason slightly rotated in the original and then visually corrected by SVG transformation. Eh.
![](Geometric_center_of_Prague/polygon_with_center_in_geometry_thumb.jpg)
Zoomed in, you can see where the center of the polygon actually is:
![](Geometric_center_of_Prague/polygon_with_center_in_geometry_zoomed_thumb.jpg)
Results
![](Geometric_center_of_Prague/polygon_with_center_in_geometry_zoomed2.jpg)
Which is by my estimation 50.0579333N, 14.4434400E.
![](Geometric_center_of_Prague/seznam_mapy.jpg)
Quite different point, eh? I find it funny that it is in the middle of the street.
![](Geometric_center_of_Prague/difference_thumb.jpg)
On the left is the point found by me, on the right by the Kluci z Prahy.
Definition of the center
It doesn't matter where the center really is. No matter what, it will depend on the person interpreting the meaning of "center". Someone will see it in the point where north-south and east-west lines cross. Someone will see it in the center of geometry. And psychologically, I would point out to an entirely different place on the map, which feels more in the center.
![](Geometric_center_of_Prague/centers_thumb.jpg)
I've enjoyed looking for the geometric center. It feels nice to be able to do things like this, and utlize Blender to whatever I need at that time.
Source
Blender file:
If you want to get a set of points that define the polygon of the map, you can use following script. Note: it works only if you have the SVG curve selected.
import bpy
obdata = bpy.context.object.data
curve = bpy.context.object
deg = bpy.context.evaluated_depsgraph_get()
me = bpy.data.meshes.new_from_object(curve.evaluated_get(deg), depsgraph=deg)
map_mesh = bpy.data.objects.new(curve.name + "_mesh", me)
print(dir(map_mesh.data))
for v in map_mesh.data.vertices:
print('{:.2f} {:.2f}'.format(v.index, v.co.x * 10000 + 700, v.co.y * 10000 + 500))