tchenkov

L04u13_PointInTheFigure

Jan 23rd, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.34 KB | None | 0 0
  1. package Uprajneniq;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by todor on 23.01.2017 г..
  7.  */
  8. public class u13_PointInTheFigure {
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scan = new Scanner(System.in);
  12.  
  13.         int blockSize = Integer.parseInt(scan.nextLine());
  14.         int dotX = Integer.parseInt(scan.nextLine());
  15.         int dotY = Integer.parseInt(scan.nextLine());
  16.  
  17.         int parametersBottom[] = FigureParameters(blockSize, dotX, dotY, true);
  18.         int parametersTop[] = FigureParameters(blockSize, dotX, dotY, false);
  19.  
  20.         boolean isDotInBottomHalf = IsDotInsideHalfFigure(parametersBottom);
  21.         boolean isDotInTopHalfI = IsDotInsideHalfFigure(parametersTop);
  22.         boolean isInFigure = isDotInBottomHalf || isDotInTopHalfI;
  23.  
  24.         if (isInFigure ) {
  25.  
  26.             boolean isDotOnBottomHalfBorder = IsDotOnBorder(parametersBottom);
  27.             boolean isDotOnTopHalfBorder = IsDotOnBorder(parametersTop);
  28.             boolean isDotOnBorder = isDotOnBottomHalfBorder || isDotOnTopHalfBorder;
  29.  
  30.             int commonLineX1 = blockSize;
  31.             int commonLineX2 = blockSize * 2;
  32.             int commonLineY = blockSize;
  33.             boolean isDotOnCommonSide = dotY == commonLineY && (commonLineX1 < dotX && dotX < commonLineX2);
  34.             if (isDotOnBorder && !isDotOnCommonSide) {
  35.                 System.out.println("border");
  36.             }
  37.             else {
  38.                 System.out.println("inside");
  39.             }
  40.  
  41.         }
  42.         else {
  43.             System.out.println("outside");
  44.         }
  45.     }
  46.  
  47.     static boolean IsDotInsideHalfFigure(int figureAndDotCoordinates[]) {
  48.  
  49.         int x1 = figureAndDotCoordinates[0];
  50.         int y1 = figureAndDotCoordinates[1];
  51.         int x2 = figureAndDotCoordinates[2];
  52.         int y2 = figureAndDotCoordinates[3];
  53.         int x = figureAndDotCoordinates[4];
  54.         int y = figureAndDotCoordinates[5];
  55.  
  56.         boolean isInRectangle = (x1 <= x && x <= x2) && (y1 <= y && y <= y2);
  57.  
  58.         return  isInRectangle;
  59.     }
  60.  
  61.     static boolean IsDotOnBorder(int figureAndDotCoordinates[]) {
  62.         int x1 = figureAndDotCoordinates[0];
  63.         int y1 = figureAndDotCoordinates[1];
  64.         int x2 = figureAndDotCoordinates[2];
  65.         int y2 = figureAndDotCoordinates[3];
  66.         int x = figureAndDotCoordinates[4];
  67.         int y = figureAndDotCoordinates[5];
  68.  
  69.         boolean isOnLeftBorder = x == x1 && (y1 <= y && y <= y2);
  70.         boolean isOnRightBorder = x == x2 && (y1 <= y && y <= y2);
  71.         boolean isOnTopBorder = y == y1 && (x1 <= x && x <= x2);
  72.         boolean isOnBottomBorder = y == y2 && (x1 <= x && x <= x2);
  73.  
  74.         boolean isOnAnyBorder = isOnLeftBorder || isOnRightBorder || isOnTopBorder || isOnBottomBorder;
  75.  
  76.         return isOnAnyBorder;
  77.     }
  78.  
  79.     static int[] FigureParameters (int size, int dotX, int dotY, boolean isBottom) {
  80.  
  81.         int[] parameters = new int[6];
  82.         if (isBottom) {
  83.             parameters[0] = 0;
  84.             parameters[1] = 0;
  85.             parameters[2] = size * 3;
  86.             parameters[3] = size;
  87.         }
  88.         else {
  89.             parameters[0] = size;
  90.             parameters[1] = size;
  91.             parameters[2] = size * 2;
  92.             parameters[3] = size * 4;
  93.         }
  94.  
  95.         parameters[4] = dotX;
  96.         parameters[5] = dotY;
  97.  
  98.         return parameters;
  99.     }
  100. }
Add Comment
Please, Sign In to add comment