I don't think this is a programming problem, but a basic geometry one.
You've got 7 points in that configuration and you want to find some geometric properties which are robust to rotation. The first thing I can think of is distance.
- Compute the squared distance (SD) between all points, then find the one which maximizes the sum of squared distances (SSD) to all others. That point is P7.
- Find the one with maximum SD from P7. That point is P1.
- Find the one with minimum SD from P7. That point is P6.
- Find the one with second minimum SD from P7. That point is P5.
- Find the one with minimum SD from P1. That point is P2.
In order to find P3 and P4 you need to detect a side (left/right) with respect to a direction. Let's call Q and R the two unknown points and a direction we are already sure of, such as the one from 1 to 7. You can now look at the sign of the cross product between vector from P1 to P7 and the one from P1 to Q. If it's at the right, the value will be positive. So we are able to find its identity.
if ( (Q.x - P1.x) * (P2.y - P1.x) - (Q.y - P1.y) * (P2.x - P1.x) > 0) {
P3 = Q;
P4 = R;
}
else {
P3 = R;
P4 = Q;
}