AOJ Problem 0081 : A Symmetric Point

0番で解いてないのをチマチマ埋める。

404 Not Found

対称な位置にある点を求める。学校では最近習ったりもした。

何も使わず、面倒くさい手計算をして点rと与えられた直線との直交点を求めてからそれを内分するもう片方の点を求めれる式をつくった。

直線が軸に対して垂直だったり平行だったりする時は例外処理。

#include <iostream>
#include <sstream>
using namespace std;
struct P{double x,y;};

void output(double x,double y){
	printf("%.6lf %.6lf\n",x,y);
}
int main(){
	P a,b,r; string s;
	while(getline(cin,s)){
		while(~s.find(","))s[s.find(",")] = ' ';
		stringstream ss(s);
		ss >> a.x >> a.y >> b.x >> b.y >> r.x >> r.y;
		
		double x , y , X = a.x-b.x , Y = a.y-b.y;
		if(X == 0){
			output(2*a.x-r.x,r.y);
		}else if(Y == 0){
			output(r.x,2*a.y-r.y );
		}else{
			x = ( r.y -a.y + (Y/X)*a.x + (X/Y)*r.x ) / ( (X*X+Y*Y)/(X*Y) );
			y = (Y/X)*(x-a.x) + a.y;
			output(2*x-r.x,2*y-r.y);
		}
	}
}