Skip to content

Instantly share code, notes, and snippets.

@ateruimashin
Created October 11, 2018 08:08
Show Gist options
  • Save ateruimashin/83d15bb8fc96474f4ccf9dcfcc423cfa to your computer and use it in GitHub Desktop.
Save ateruimashin/83d15bb8fc96474f4ccf9dcfcc423cfa to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char const *argv[]) {
double x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
double dis,a,x3,y3,x4,y4;
dis=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
if(x1!=x2){
a=(y1-y2)/(x1-x2);
if(a!=0){
if(y1<=y2){
x4=x1-dis*sqrt(pow(a,2)/(pow(a,2)+1));
y4=(x1-x4)/a+y1;
x3=x2+(x4-x1);
y3=y2+(y4-y1);
}else{
x4=x1+dis*sqrt(pow(a,2)/(pow(a,2)+1));
y4=(x1-x4)/a+y1;
x3=x2+(x4-x1);
y3=y2+(y4-y1);
}
}else{
x3=x2;
x4=x1;
if(x1<x2){
y3=y2+dis;
y4=y3;
}else{
y3=y2-dis;
y4=y3;
}
}
}else{
y3=y2;
y4=y1;
if(y1<y2){
x3=x2-dis;
x4=x1-dis;
}else{
x3=x2+dis;
x4=x1+dis;
}
}
printf("%.0f %.0f %.0f %.0f\n",x3,y3,x4,y4);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment