storing those points that are not in triangles
I have written a code which first get some points(has x ,y) and then I will check all possible triangles with those points and I will check that the specific point is in a triangle or not(with determinate) but I have problem with this part of code which finds the external points and internal points.it doesn't work well.please help me thanks.
public void externalPoints(List<Point> pointList) {
// this method will check that a point is in a (n-1)(n-2)(n-3)/6 triangles or not
int n = pointList.size();
if (n <= 2) {
System.out.println("null");
} else if (n == 3) {
d开发者_运维技巧rawingLine();
} else {
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j++) {
for (int k = 2; k < n; k++) {
for (int m = 3; m < n; m++) {
if (isPointInTriangle(pointList.get(i), pointList.get(j), pointList.get(k), pointList.get(m)) == true) {
System.out.println("is in the triangle");
break;
} else {
System.out.println("is not in a triangle");
newList.add(pointList.get(i));
}
}
}
}
}
}
}
Also isInTriangle
method is like this site :link text
Can you explain why it isn't working well?
It seems that your method of iterating over points is a little dodgy. For example, if n == 5, your program will evaluate isPointInTriangle for i = j = k = m = 4, meaning that it's trying to figure out whether Point 4 is inside a triangle formed from vertices 4,4,4. If you're using the first method in your link, isPointInTriangle(4,4,4,4) will return true, even though the shape you gave it isn't actually a triangle... you probably want to assert that your vertices are distinct points.
精彩评论