Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- struct Point {
- double x,y;
- void read()
- {
- scanf("%lf%lf",&x,&y);
- }
- Point operator-(Point a)
- {
- Point res;
- res.x=x-a.x;
- res.y=y-a.y;
- return res;
- }
- double operator*(Point a)
- {
- return x*a.y-y*a.x;
- }
- double scal(Point a)
- {
- return x*a.x+y*a.y;
- }
- double dist(Point a)
- {
- return sqrt((a.x-x)*(a.x-x) + (a.y-y)*(a.y-y));
- }
- };
- int main()
- {
- // freopen("distance.in","r",stdin);
- // freopen("distance2.out","w",stdout);
- Point p1,p2,p;
- p.read();
- p1.read(); p2.read();
- 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)));
- }
Advertisement
Add Comment
Please, Sign In to add comment