ArtemisL2

Untitled

Aug 5th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8. double x = sc.nextInt();
  9. double y = sc.nextInt();
  10. double x1 = sc.nextInt();
  11. double y1 = sc.nextInt();
  12. double x2 = sc.nextInt();
  13. double y2 = sc.nextInt();
  14.  
  15. double xv = x2-x1;
  16. double yv = y2-y1;
  17. double xv2 = x-x1;
  18. double yv2 = y-y1;
  19. double SP = (xv*xv2)+(yv*yv2);
  20.  
  21. double xv1 = x1-x2;
  22. double yv1 = y1-y2;
  23. double xv21 = x-x2;
  24. double yv21 = y-y2;
  25. double SP1 = (xv1* xv21)+(yv1*yv21);
  26.  
  27. double a = y1-y2;
  28. double b = x2-x1;
  29. double c = (x1*y2)-(x2*y1);
  30.  
  31. if ((SP1 >= 0) && SP >= 0){
  32. double AP = Math.abs(a*x+b*y+c)/Math.sqrt((a*a)+b*b);
  33. System.out.println(AP);
  34. } else {
  35. double vnx = x2-x;
  36. double vny = y2-y;
  37. double vnx1 = x1-x;
  38. double vny1 = y1-y;
  39. double ga1 = Math.sqrt((vnx*vnx)+(vny*vny));
  40. double ga2 = Math.sqrt((vnx1*vnx1)+(vny1*vny1));
  41.  
  42. if (ga1 < ga2){
  43. System.out.println(ga1);
  44. } else {
  45. System.out.println(ga2);
  46. }
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment