Bystroushaak's blog / English section / 3D modeling / Geometric center of Prague

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?

(Source of the image: https://www.youtube.com/watch?v=Hj5V6Gh0mOs)

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:

(Source: https://img.kurzy.cz/mapa/pr/slepa/praha-okres.svg, licensed under CC BY SA.)

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:

Scaled up:

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.

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:

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.

(Source of map: https://www.praha.eu/public/89/6a/ec/1099205_140344_cyklomapa_Praha_50_2010_MAPA_strana_1.jpg)

Zoomed in, you can see where the center of the polygon actually is:

(Source of map: https://www.praha.eu/public/89/6a/ec/1099205_140344_cyklomapa_Praha_50_2010_MAPA_strana_1.jpg)

Results

(Source: https://www.praha.eu/public/89/6a/ec/1099205_140344_cyklomapa_Praha_50_2010_MAPA_strana_1.jpg)

Which is by my estimation 50.0579333N, 14.4434400E.

(Source: http://mapy.cz)

Quite different point, eh? I find it funny that it is in the middle of the street.

(Source: http://mapy.cz)

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.

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:

http://kitakitsune.org/storage/notion_retardace/geometricky_stred_prahy/geometricky_stred_prahy.blend

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))
Become a Patron