Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This program determines if 2 triangles are congruent given their vertexes.
- // Author: Eyal Oren
- // Date:
- import java.util.Scanner;
- public class Congruent
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in); ////Creating a scanner to take input from user.
- System.out.println("This program determines if two triangles are congruent, given "
- + " their vertexes.");
- System.out.println("Please enter the three vertexes "
- + "of each triangle.");
- // Defining the vertexes type, and asking the user for their value.
- double x11 = scan.nextDouble();
- double y11 = scan.nextDouble();
- double x12 = scan.nextDouble();
- double y12 = scan.nextDouble();
- double x13 = scan.nextDouble();
- double y13 = scan.nextDouble();
- double x21 = scan.nextDouble();
- double y21 = scan.nextDouble();
- double x22 = scan.nextDouble();
- double y22 = scan.nextDouble();
- double x23 = scan.nextDouble();
- double y23 = scan.nextDouble();
- double a1, b1,c1, a2, b2, c2; //Defining the type of the three lengths of each triangle.
- //Calculating the lenghts using Distance equation.
- a1 = Math.sqrt(Math.pow(x11-x12,2) + Math.pow(y11-y12,2));
- b1 = Math.sqrt(Math.pow(x11-x13,2) + Math.pow(y11-y13,2));
- c1 = Math.sqrt(Math.pow(x12-x13,2) + Math.pow(y12-y13,2));
- a2 = Math.sqrt(Math.pow(x21-x22,2) + Math.pow(y21-y22,2));
- b2 = Math.sqrt(Math.pow(x21-x23,2) + Math.pow(y21-y23,2));
- c2 = Math.sqrt(Math.pow(x22-x23,2) + Math.pow(y22-y23,2));
- //Creating the condition to determine if the two triangles are congruent.
- if( (a1 == a2 && b1 == b2 && c1 == c2) ||
- (a1 == a2 && b1 == c2 && c1 == b2) ||
- (a1 == b2 && b1 == a2 && c1 == c2) ||
- (a1 == c2 && b1 == b2 && c1 == a2) ||
- (a1 == c2 && b1 == a2 && c1 == b2) ||
- (a1 == b2 && b1 == c2 && c1 == a2) )
- System.out.println("The triangles are congruent");
- else
- System.out.println("The triangles aren't congruent");
- } //end of method main
- } //end of class Congruent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement