Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("distantapunctdreapta.in");
- ofstream fout("distantapunctdreapta.out");
- void getLine(int x1, int y1, int x2, int y2, int &a, int &b, int &c)
- {
- /// (x- p1X) / (p2X - p1X) = (y - p1Y) / (p2Y - p1Y)
- a = y1 - y2;
- b = x2 - x1;
- c = x1 * y2 - x2 * y1;
- }
- double dist(int pct1X, int pct1Y, int pct2X, int pct2Y, int pct3X, int pct3Y)
- {
- int a, b, c;
- getLine(pct2X, pct2Y, pct3X, pct3Y, a, b, c);
- return abs(a * pct1X + b * pct1Y + c) / sqrt(a * a + b * b);
- }
- int main()
- {
- int x1,y1,x2,y2,x3,y3;
- double d;
- fin>>x1>>y1>>x2>>y2>>x3>>y3;
- d=dist(x1,y1,x2,y2,x3,y3);
- d=floor(d*100)/100;
- fout<<setprecision(2)<<fixed<<d;
- return 0;
- }
Add Comment
Please, Sign In to add comment