Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Main {
  public static void main(String[] args) {
    
    DistanceFormula(3, 2.5, -1, 2.5);
  }
  private static void DistanceFormula(double x1, double y1, double x2, double y2) {
     //*******************************************************
      //Calculating Distance from points A = (x2, y2) & B = (x2, y2) & C = (x3, y3)
      //Used distance formula
      double length_ab = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
      double distance = length_ab*24;
      double length_bc = Math.sqrt(Math.pow((x2 - x2), 2) + Math.pow((y2 - y1), 2));
      //*******************************************************
      double angle_b = Math.rint(Math.toDegrees(Math.acos(length_bc/length_ab))); //adj/hyp
      //*********************************************************
      double turn_angle = 0.000;
      if (x1 <= x2) {
        if (y1 <= y2) {
          turn_angle = -(angle_b);
        }

        else if (y1 > y2) {
          turn_angle = -(180-angle_b);
        }
         
      }

      else if (x1 > x2) {
        if (y1 <= y2) {
          turn_angle = -angle_b;
        }

        else if (y1 > y2) {
          turn_angle = -(angle_b -180);
        }
      }
      //Printing all statements
      System.out.println(distance);
      System.out.println(turn_angle);
  }

}