fork download
  1. import java.util.*;
  2. import java.lang.Math.*;
  3. import java.io.*;
  4.  
  5. class geomVector
  6. {
  7. public double x1,x2,y1,y2,xV,yV,xM,yM,vL;
  8. public void setVector(double a1,double b1, double a2, double b2)
  9. {
  10. x1 = a1;
  11. x2 = a2;
  12. y1 = b1;
  13. y2 = b2;
  14. }
  15. public void getVectorCoords()
  16. {
  17. xV = x2 - x1;
  18. yV = y2 - y1;
  19. }
  20. public void getMiddleCoords()
  21. {
  22. getVectorCoords();
  23. xM = xV/2;
  24. yM = yV/2;
  25. }
  26. public void multiplyVector(double a)
  27. {
  28. x1*=a;
  29. x2*=a;
  30. y1*=a;
  31. y2*=a;
  32. getVectorCoords();
  33. getMiddleCoords();
  34. }
  35. public double getLength()
  36. {
  37. return vL = Math.sqrt(xV*xV+yV*yV);
  38. }
  39. public void vectorSum(geomVector a,geomVector b)
  40. {
  41. a.setVector(a.x1,a.y1,b.x2,b.y2);
  42. }
  43. public double scalMult(geomVector a,geomVector b)
  44. {
  45. return (a.xV*b.xV+a.yV*b.yV);
  46. }
  47. public double getAngle(geomVector a, geomVector b)
  48. {
  49. return Math.acos(scalMult(a,b)/(a.getLength()*b.getLength()));
  50. }
  51. }
  52.  
  53. public class Main {
  54. public static void main(String[] args)
  55. {
  56. double x1,x2,x3,x4,y1,y2,y3,y4;
  57. Scanner in = new Scanner(System.in);
  58. x1 = in.nextDouble();
  59. x2 = in.nextDouble();
  60. x3 = in.nextDouble();
  61. x4 = in.nextDouble();
  62. y1 = in.nextDouble();
  63. y2 = in.nextDouble();
  64. y3 = in.nextDouble();
  65. y4 = in.nextDouble();
  66. geomVector a = new geomVector();
  67. geomVector b = new geomVector();
  68. a.setVector(x1,y1,x2,y2);
  69. b.setVector(x3,y3,x4,y4);
  70. a.getVectorCoords();
  71. b.getVectorCoords();
  72. System.out.println(b.scalMult(b,a));
  73. System.out.println(a.getAngle(a,b));
  74. }
  75. }
Success #stdin #stdout 0.08s 4386816KB
stdin
4 61 44 21 4 12 65 51
stdout
-1423.0
2.7342438697918836