Skip to content
Advertisement

Calculate distance between points in polygon

I found a lot of posts on how to calculate distance between two points or from one point to polygon but I simply can’t find how to calculate distance of each edge. I have a polygon, where the coordinates are these:

JavaScript

I simply want to calculate length of each edge. Maybe I should use (math.dist(p, q)) with for loop or something?

Advertisement

Answer

If points coordinates are stored in two python lists x and y, then you can calculate each edge length with:

JavaScript

The append is required in order to close the polygon and calculate all edges length. With points you provided above, the edges distances are:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement