rotti321

DistantaPunctDreapta

Aug 15th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("distantapunctdreapta.in");
  5. ofstream fout("distantapunctdreapta.out");
  6.  
  7. void getLine(int x1, int y1, int x2, int y2, int &a, int &b, int &c)
  8. {
  9.     /// (x- p1X) / (p2X - p1X) = (y - p1Y) / (p2Y - p1Y)
  10.     a = y1 - y2;
  11.     b = x2 - x1;
  12.     c = x1 * y2 - x2 * y1;
  13. }
  14.  
  15. double dist(int pct1X, int pct1Y, int pct2X, int pct2Y, int pct3X, int pct3Y)
  16. {
  17.     int a, b, c;
  18.     getLine(pct2X, pct2Y, pct3X, pct3Y, a, b, c);
  19.     return abs(a * pct1X + b * pct1Y + c) / sqrt(a * a + b * b);
  20. }
  21.  
  22. int main()
  23. {
  24.     int x1,y1,x2,y2,x3,y3;
  25.     double d;
  26.     fin>>x1>>y1>>x2>>y2>>x3>>y3;
  27.     d=dist(x1,y1,x2,y2,x3,y3);
  28.     d=floor(d*100)/100;
  29.     fout<<setprecision(2)<<fixed<<d;
  30.  
  31.     return 0;
  32. }
Add Comment
Please, Sign In to add comment