IRusev

Problem 9. ** Points inside the House

Sep 9th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class PointsInsideTheHouse {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Locale.setDefault(new Locale("en", "US"));
  10. Scanner input = new Scanner(System.in);
  11.  
  12. double x = input.nextDouble();
  13. double y = input.nextDouble();
  14.  
  15. double pointAX = 12.5;
  16. double pointAY = 8.5;
  17.  
  18. double pointBX = 22.5;
  19. double pointBY = 8.5;
  20.  
  21. double pointCX = 17.5;
  22. double pointCY = 3.5;
  23.  
  24. double ABC = Math.abs(pointAX * (pointBY - pointCY) + pointBX * (pointCY - pointAY) + pointCX * (pointAY - pointBY));
  25. double ABP = Math.abs(pointAX * (pointBY - y) + pointBX * (y - pointAY) + x * (pointAY - pointBY));
  26. double APC = Math.abs(pointAX * (y - pointCY) + x * (pointCY - pointAY) + pointCX * (pointAY - y));
  27. double PBC = Math.abs(x * (pointBY - pointCY) + pointBX * (pointCY - y) + pointCX * (y - pointBY));
  28. boolean isInTriangle = ABP + APC + PBC == ABC;
  29.  
  30. if (x >= 12.5 && x <= 22.5 && y >= 8.5 && y <= 13.5) {
  31.  
  32. if (x > 17.5 && x < 20.0 && y > 8.5 && y < 13.5) {
  33. System.out.println("Outside");
  34. }else{
  35. System.out.println("Inside");
  36. }
  37. }else if(isInTriangle){
  38. System.out.println("Inside");
  39. }
  40. else{
  41. System.out.println("Outside");
  42. }
  43. input.close();
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment