How to get all n sets of three consecutives elements in an array or arraylist with a for statement ?
Posted
by newba
on Stack Overflow
See other posts from Stack Overflow
or by newba
Published on 2010-04-30T04:29:45Z
Indexed on
2010/04/30
4:37 UTC
Read the original article
Hit count: 244
Hi,
I'm trying to do a convex hull approach and the little problem is that I need to get all sets of three consecutive vertices, like this:
private void isConvexHull(Ponto[] points) {
Arrays.sort(points);
for (int i = 0; i <points.length; i++) {
isClockWise(points[i],points[i+1],points[i+2]);
}
//...
}
I always do something that I don't consider clean code. Could please help me find one or more ways to this? I want it to be circular, i.e., if my fisrt point of the a set is the last element in the array, the 2nd element will be the 3rd in the list and the 3rd in that set will be the the 2nd element in the list, and so on. They must be consecutive, that's all.
© Stack Overflow or respective owner