Advertisement
Guest User

09.PointsInsideTheHouse

a guest
May 12th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class PointsInsideTheHouse {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         String[] vars = input.nextLine().split(" ");
  9.         int x = Integer.parseInt(vars[0]);
  10.         int y = Integer.parseInt(vars[1]);         
  11.         double x1 = 12.5, y1 = 8.5;
  12.         double x2 = 17.5, y2 = 3.5;
  13.         double x3 = 22.5, y3 = 8.5;
  14.         double ABC = Math.abs (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
  15.         double ABP = Math.abs (x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2));
  16.         double APC = Math.abs (x1 * (y - y3) + x * (y3 - y1) + x3 * (y1 - y));
  17.         double PBC = Math.abs (x * (y2 - y3) + x2 * (y3 - y) + x3 * (y - y2));
  18.         boolean isInTriangle = ABP + APC + PBC == ABC;
  19.         if((x>=12.5 && x<=17.5) && (y<=13.5 && y>=8.5)) {
  20.             System.out.println("Inside");
  21.         }
  22.         else if((x>=20 && x<=22.5) && (y<=13.5 && y>=8.5)) {
  23.             System.out.println("Inside");
  24.         }
  25.  
  26.         else if(isInTriangle){
  27.             System.out.println("Inside");
  28.         }
  29.         else {
  30.             System.out.println("Outside");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement