Advertisement
n_stefanov

Ex9_PointsInsideHouse

May 13th, 2014
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package javaSyntax;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex9_PointsInsideHouse {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner in = new Scanner(System.in);
  10.         double x = in.nextDouble();
  11.         double y = in.nextDouble();
  12.  
  13.         double x1 = 12.5, y1 = 8.5;
  14.         double x2 = 17.5, y2 = 3.5;
  15.         double x3 = 22.5, y3 = 8.5;
  16.  
  17.         double abc = Math.abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
  18.         double abp = Math.abs(x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2));
  19.         double apc = Math.abs(x1 * (y - y3) + x * (y3 - y1) + x3 * (y1 - y));
  20.         double pbc = Math.abs(x * (y2 - y3) + x2 * (y3 - y) + x3 * (y - y2));
  21.  
  22.         boolean isInTriangle = false;
  23.         if (abp + apc + pbc == abc) {
  24.             isInTriangle = true;
  25.         }
  26.  
  27.         if ((x >= 12.5 && x <= 17.5) && (y <= 13.5 && y >= 8.5)) {
  28.             System.out.println("Inside");
  29.         } else if ((x >= 20 && x <= 22.5) && (y <= 13.5 && y >= 8.5)) {
  30.             System.out.println("Inside");
  31.         } else if (isInTriangle) {
  32.             System.out.println("Inside");
  33.         } else {
  34.             System.out.println("Outside");
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement