Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem_9_PointsInsideTheHouse {
- public static void main(String[] args) {
- Scanner scanner= new Scanner(System.in);
- double aX= 12.5;
- double aY= 8.5;
- double bX= 22.5;
- double bY= 8.5;
- double cX= 17.5;
- double cY= 3.5;
- System.out.print("Ox= ");
- double oX= scanner.nextDouble();
- System.out.print("Oy= ");
- double oY= scanner.nextDouble();
- double area= Math.abs(((aX * ((bY - cY))) + (bX * ((cY - aY))) + (cX * ((aY - bY)))) / 2);
- // If the point is in the triangle it is possible to create 3 sub triangles. The sum of their areas is equal to area of the greater triangle.
- double area1= Math.abs(((aX * ((bY - oY))) + (bX * ((oY - aY))) + (oX * ((aY - bY)))) / 2);
- double area2= Math.abs(((aX * ((oY - cY))) + (oX * ((cY - aY))) + (cX * ((aY - oY)))) / 2);
- double area3= Math.abs(((oX * ((bY - cY))) + (bX * ((cY - oY))) + (cX * ((oY - bY)))) / 2);
- double sumAreas= area1 + area2 + area3;
- if (sumAreas == area) {
- System.out.print("Inside");
- }
- else {
- if (oX >= 12.5 && oX <= 17.5 && oY >= 8.5 && oY <= 13.5) {
- System.out.print("Inside");
- }
- else {
- if (oX >= 20 && oX <= 22.5 && oY >= 8.5 && oY <= 13.5) {
- System.out.print("Inside");
- }
- else {
- System.out.print("Outside");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement