makesz1
makesz1

Reputation: 43

Java: Perimeter of a convex polygon

I have an ArrayList of some Point-s. It's guaranteed that the Points are part of a convex polygon.

How can I calculate the perimeter of this convex polygon?

Update: The Points in the ArrayList are out of any order

Update 2: All the points are part of the convex polygon's edge

Upvotes: 0

Views: 577

Answers (3)

Durandal
Durandal

Reputation: 20069

If the points are not ordered, its impossible without determining the correct order. Thats because if there are more than 3 points there is more than one polygon they could form.

I'm not entirely sure the constraint that the points are forming a convex polygon is sufficient to determine a canonic shape from the point cloud.

My guess is that by taking a random point from the list, and then looking for the nearest remaining point you can build a canonic order. From there its just summing up the length of the lines formed by consecutive points.

Edit: On second thought, scratch that idea. It won't work for all cases. That leaves you with permuting the points and checking if the formed polygon is indeed convex.

The question on how to check if a polygon is convex has been asked and answered here: How do determine if a polygon is complex/convex/nonconvex?

Upvotes: 0

copeg
copeg

Reputation: 8348

Sum the distance between each two consecutive points.

Upvotes: 1

ControlAltDel
ControlAltDel

Reputation: 35106

Are the points in order? If so, you just need to sum up the distance from each vertex to the next

Upvotes: 1

Related Questions