I have a set of points (black dots in geographic coordinate value) derived from the convex hull (blue) of a polygon (red). see Figure:
[(560023.44957588764,6362057.3904932579),
(560023.44957588764,6362060.3904932579),
(560024.44957588764,6362063.3904932579),
(560026.94957588764,6362068.3904932579),
(560028.44957588764,6362069.8904932579),
(560034.94957588764,6362071.8904932579),
(560036.44957588764,6362071.8904932579),
(560037.44957588764,6362070.3904932579),
(560037.44957588764,6362064.8904932579),
(560036.44957588764,6362063.3904932579),
(560034.94957588764,6362061.3904932579),
(560026.94957588764,6362057.8904932579),
(560025.44957588764,6362057.3904932579),
(560023.44957588764,6362057.3904932579)]
I need to calculate the the major and minor axis length following these steps (form this post write in R-project and in Java) or following the this example procedure
- Compute the convex hull of the cloud.
- For each edge of the convex hull:
2a. compute the edge orientation,
2b. rotate the convex hull using this orientation in order to compute easily the bounding rectangle area with min/max of x/y of the rotated convex hull,
2c. Store the orientation corresponding to the minimum area found, - Return the rectangle corresponding to the minimum area found.
After that we know the The angle Theta (represented the orientation of the bounding rectangle relative to the y-axis of the image). The minimum and maximum of a and b over all boundary points are
found:
- a(xi,yi) = xi*cos Theta + yi sin Theta
- b(xi,yi) = xi*sin Theta + yi cos Theta
The values (a_max – a_min) and (b_max – b_min) defined the length and width, respectively,
of the bounding rectangle for a direction Theta.
Best Answer
I just implemented this myself, so I figured I'd drop my version here for others to view:
Here are four different examples of it in action. For each example, I generated 4 random points and found the bounding box.
(edit by @heltonbiker) A simple code for plotting:
(end edit)
It's relatively quick too for these samples on 4 points:
Link to the same answer over on gis.stackexchange for my own reference.