Madiyar

Untitled

Nov 16th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. struct Point {
  5. double x,y;
  6. void read()
  7. {
  8. scanf("%lf%lf",&x,&y);
  9. }
  10. Point operator-(Point a)
  11. {
  12. Point res;
  13. res.x=x-a.x;
  14. res.y=y-a.y;
  15. return res;
  16. }
  17. double operator*(Point a)
  18. {
  19. return x*a.y-y*a.x;
  20. }
  21.  
  22. double scal(Point a)
  23. {
  24. return x*a.x+y*a.y;
  25. }
  26.  
  27. double dist(Point a)
  28. {
  29. return sqrt((a.x-x)*(a.x-x) + (a.y-y)*(a.y-y));
  30. }
  31.  
  32.  
  33. };
  34. int main()
  35. {
  36. // freopen("distance.in","r",stdin);
  37. // freopen("distance2.out","w",stdout);
  38. Point p1,p2,p;
  39. p.read();
  40. p1.read(); p2.read();
  41. if ((p2-p1).scal(p-p1) >= 0 && (p-p2).scal(p1-p2) >= 0) printf("%.6lf",abs((p2-p1)*(p-p1))/p2.dist(p1)); else printf("%.6lf",min(p.dist(p1),p.dist(p2)));
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment