fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define pi 3.14159265358979323846
  4.  
  5. double sphere_distance(double x1, double y1, double z1, double x2, double y2, double z2){
  6. double r, o1, o2, f1, f2;
  7. r = pow(x1*x1+y1*y1+z1*z1, 0.5);
  8. o1 = acos(z1/r);
  9. o2 = acos(z2/r);
  10. f1 = atan2(y1,x1);
  11. f2 = atan2(y2,x2);
  12.  
  13. printf("r is: %lf\n", r);
  14. printf("o1 is: %lf\n", o1);
  15. printf("o2 is: %lf\n", o2);
  16. printf("f1 is: %lf\n", f1);
  17. printf("f2 is: %lf\n", f2);
  18.  
  19. return r*acos(cos(o1)*cos(o2)+sin(o1)*sin(o2)*cos(f1-f2));
  20. }
  21.  
  22. int main(){
  23. double x1,y1,z1,x2,y2,z2;
  24. scanf("%lf %lf %lf\n %lf %lf %lf", &x1, &y1, &z1, &x2, &y2, &z2);
  25. printf("distance is: %lf", sphere_distance(x1,y1,z1,x2,y2,z2));
  26. return 0;
  27. }
Success #stdin #stdout 0s 2296KB
stdin
-1 1 -1
1 1 1
stdout
r is: 1.732051
o1 is: 2.186276
o2 is: 0.955317
f1 is: 2.356194
f2 is: 0.785398
distance is: 3.309314