BB
BAN USERI am a student.
Ok i've done the first part, but i don't understand how to add flood fill part in my code. Can you help me?
public static boolean isItInTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x4 = 0;
int y4 = 0;
try {
System.out.println("Write the x coordinate for point P");
x4 = Integer.parseInt(br.readLine());
System.out.println("Write the y coordinate for point P");
y4 = Integer.parseInt(br.readLine());
} catch (Exception e) {
}
int ABC = Math.abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))/2;
int PBC = Math.abs(x4 * (y2 - y3) + x2 * (y3 - y4) + x3 * (y4 - y2))/2;
int APC = Math.abs(x1 * (y4 - y3) + x4 * (y3 - y1) + x3 * (y1 - y4))/2;
int ABP = Math.abs(x1 * (y2 - y4) + x2 * (y4 - y1) + x4 * (y1 - y2))/2;
if (ABC == PBC + APC + ABP) {
System.out.println("P in inside the ABC");
return true;
} else {
System.out.println("P is not inside the ABC");
return false;
}
}
This does exactly the same my code does. Check if some point is inside the triangle. We need to return ALL the points inside.
- BB December 29, 2013