/* * Problem 2, Part 2, Lab 7, Wednesday, 24-09-2008 Use this modified Triangle class to develop a program which will take as input the coor- dinates of the three points of the triangle A, and a point r. (Total eight command line arguments). The program should prints the the following output with suitable messages. • Area of triangle A. • Perimeter of triangle A. • Whether point r lies within triangle A or not. • Whether line segment passing through (5, 0) and (0, 5) is parallel to any of the sides of triangle A or not. • Whether line segment passing through points (0, 0) and (5, 5) intersects any of the sides of triangle A or not. */ package Geometry; class TestGeometry { public static void main(String[] args) { if(args.length != 8) { System.out.println("Invalid No of Command line parameters"); System.out.println("Usage :: java ./TestTriangle "); return; } double x1,y1,x2,y2,x3,y3,x4,y4; try { x1 = Double.parseDouble(args[0]); y1 = Double.parseDouble(args[1]); x2 = Double.parseDouble(args[2]); y2 = Double.parseDouble(args[3]); x3 = Double.parseDouble(args[4]); y3 = Double.parseDouble(args[5]); x4 = Double.parseDouble(args[6]); y4 = Double.parseDouble(args[7]); } catch (NumberFormatException ex) { // TODO: handle exception System.out.println("NumberFormatException :: " + ex.getMessage()); return; } //Creating a Triangle object from the first three sets of coordinates from command line Triangle t1 = new Triangle(x1,y1,x2,y2,x3,y3); //Creating a point object from the last coordinate set from command line Point r = new Point(x4,y4); System.out.println("Area of triangle :: " + t1.Area()); System.out.println("Perimeter of triangle :: " + t1.Perimeter()); /* * The return value of isInside method in Triangle class is boolean. * So it can be directly used to print whether a point lies in a triangle or not */ System.out.println("Point r lies inside triangle ? :: " + t1.isInside(r)); //Creating two line segments as per given co-ordinates in the question LineSegment l1 = new LineSegment(5,0,0,5); LineSegment l2 = new LineSegment(0,0,5,5); //Creating three line segments corrosponding to the three sides of the triangle LineSegment tripq = new LineSegment(t1.getP(),t1.getQ()); LineSegment triqr = new LineSegment(t1.getQ(),t1.getR()); LineSegment trirp = new LineSegment(t1.getR(),t1.getP()); /* * The value of (l1.isParallel(tripq) || l1.isParallel(triqr) || l1.isParallel(trirp)) is true if * Line segment passing through (5,0) and (0,5) parallel to any side of the triangle else the value of the expression is false */ System.out.println("Line segment passing through (5,0) and (0,5) parallel to any side of the triangle ? :: " + (l1.isParallel(tripq) || l1.isParallel(triqr) || l1.isParallel(trirp))); /* * The value of (l2.intersects(tripq) || l2.intersects(triqr) || l2.intersects(trirp)) is true if * Line segment passing through (0,0) and (5,5) intersects any side of the triangle else the value of the expression is false */ System.out.println("Line segment passing through (0,0) and (5,5) intersects any side of the triangle ? :: " + (l2.intersects(tripq) || l2.intersects(triqr) || l2.intersects(trirp))); } }