Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package point.in.house;
- import java.util.Scanner;
- public class PointInHouse {
- public static double x1 = 12.5, y1 = 8.5;
- public static double x2 = 22.5, y2 = 8.5;
- public static double x3 = 17.5, y3 = 3.5;
- public static void main(String[] args) {
- Scanner rl = new Scanner(System.in);
- String[] points = rl.nextLine().split(" ");
- Float pointX = Float.parseFloat(points[0]);
- Float pointY = Float.parseFloat(points[1]);
- if (inMainRectangle(pointX, pointY)) {
- if (onTheDoor(pointX, pointY) || !inTriangle(pointX, pointY)) {
- System.out.println("Outside");
- } else {
- System.out.println("Inside");
- }
- } else {
- System.out.println("Outside");
- }
- }
- public static boolean inTriangle(double x, double y) {
- double ABC = Math.abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
- double ABP = Math.abs(x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2));
- double APC = Math.abs(x1 * (y - y3) + x * (y3 - y1) + x3 * (y1 - y));
- double PBC = Math.abs(x * (y2 - y3) + x2 * (y3 - y) + x3 * (y - y2));
- boolean isInTriangle = ABP + APC + PBC == ABC;
- return isInTriangle;
- }
- public static boolean inMainRectangle(double x, double y) {
- return (x >= 12.5 && x <= 22.5 && y >= 3.5 && y <= 13.5);
- }
- public static boolean onTheDoor(double x, double y) {
- return (x > 17.5 && x < 20 && y > 8.5 && y <= 13.5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement