Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Locale;
- import java.util.Scanner;
- public class PointsInsideTheHouse {
- public static void main(String[] args) {
- Locale.setDefault(new Locale("en", "US"));
- Scanner input = new Scanner(System.in);
- double x = input.nextDouble();
- double y = input.nextDouble();
- double pointAX = 12.5;
- double pointAY = 8.5;
- double pointBX = 22.5;
- double pointBY = 8.5;
- double pointCX = 17.5;
- double pointCY = 3.5;
- double ABC = Math.abs(pointAX * (pointBY - pointCY) + pointBX * (pointCY - pointAY) + pointCX * (pointAY - pointBY));
- double ABP = Math.abs(pointAX * (pointBY - y) + pointBX * (y - pointAY) + x * (pointAY - pointBY));
- double APC = Math.abs(pointAX * (y - pointCY) + x * (pointCY - pointAY) + pointCX * (pointAY - y));
- double PBC = Math.abs(x * (pointBY - pointCY) + pointBX * (pointCY - y) + pointCX * (y - pointBY));
- boolean isInTriangle = ABP + APC + PBC == ABC;
- if (x >= 12.5 && x <= 22.5 && y >= 8.5 && y <= 13.5) {
- if (x > 17.5 && x < 20.0 && y > 8.5 && y < 13.5) {
- System.out.println("Outside");
- }else{
- System.out.println("Inside");
- }
- }else if(isInTriangle){
- System.out.println("Inside");
- }
- else{
- System.out.println("Outside");
- }
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment