Problem:


線対称

平面上の異なる 3 点 P1(x1,y1), P2(x2,y2), Q(xq,yq) の座標の組を読み込んで、点 P1 点P2 を通る直線を対称軸として点 Q と線対称の位置にある点 R(x,y) を出力するプログラムを作成してください。なお、点 Q は、その対称軸上にないものとします。

入力

入力は複数のデータセットからなります。各データセットは以下の形式で与えられます。

x1,y1,x2,y2,xq,yq

x1, y1, x2, y2, xq, yq (-100 以上 100 以下の実数) がカンマ区切りで１行に与えられます。

データセットの数は 50 を超えない。

出力

データセットごとに、x, y を空白区切りで 1 行に出力する。出力は実数で 0.0001 以下の誤差を含んでもよい。

Sample Input

1.0,0.0,-1.0,0.0,1.0,1.0 
1.0,0.0,0.0,-1.0,3.0,0.0 
0.0,1.0,0.0,-1.0,1.0,1.0 

Output for the Sample Input

1.000000 -1.000000
1.000000 2.000000
-1.000000 1.000000



Sample input:
1.0,0.0,-1.0,0.0,1.0,1.0
1.0,0.0,0.0,-1.0,3.0,0.0
0.0,1.0,0.0,-1.0,1.0,1.0


Sample output:
1.000000 -1.000000
1.000000 2.000000
-1.000000 1.000000

Submission status: Accepted

Solution code:
def rot(x, y, t):
    v = [0.0, 0.0]
    v[0] = ((1-t**2)*x+2*t*y)/(t**2+1)
    v[1] = (2*t*x+(t**2-1)*y)/(t**2+1)
    return v
import sys
v=[0.0,0.0]
for line in sys.stdin:
    ipt = line.split(',')
    x = [float(ipt[i]) for i in range(0,6,2)]
    y = [float(ipt[j]) for j in range(1,6,2)]
    if x[1]!=x[0]:
        v = rot(x[2]-x[0],y[2]-y[0],(y[1]-y[0])/(x[1]-x[0]))
        v[0]+=x[0]; v[1]+=y[0];
    else:
        v = [-x[2], y[2]]
    print "%.6f %.6f"%(0.0+v[0],0.0+v[1])

Submission status: Accepted

Solution code:
def sp(a,b,c,xq,yq):
    xr = xq - 2*a*(a*xq+b*yq+c)/(a**2+b**2)
    yr = yq - 2*b*(a*xq+b*yq+c)/(a**2+b**2)
    print xr,yr

while True:
    try:
        x1,y1,x2,y2,xq,yq = map(float, raw_input().split(","))
        sp(y2-y1,-(x2-x1),x2*y1-x1*y2,xq,yq)
    except:
        break

Submission status: Accepted

Solution code:
import sys
for s in sys.stdin:
  x1,y1,x2,y2,xq,yq =map(float,s[:-1].split(","))
  if x2==x1:
    y=yq
    x=x1
  else:
    m=1.0*(y2-y1)/(x2-x1)
    a=m*m+1
    x0=m*x1-y1
    y0=xq+m*yq
    x=(m*x0+y0)/a
    y=(-x0+m*y0)/a
  print "%0.5f %0.5f"%(2*x-xq,2*y-yq)

Submission status: Accepted

Solution code:
while True:
    try:
        x1, y1, x2, y2, xp, yp = map(float, input().split(','))

        dx = x2 - x1
        dy = y2 - y1
        
        xr = (2*dx*dy*yp + (dx**2 - dy**2)*xp + 2*dy*(x1*y2 - x2*y1))/(dx**2 + dy**2)
        yr = (2*dx*dy*xp - (dx**2 - dy**2)*yp - 2*dx*(x1*y2 - x2*y1))/(dx**2 + dy**2)

        print(xr, yr)

    except EOFError:
        break

Submission status: Accepted

Solution code:
while True :
    try :
        x1, y1, x2, y2, xq, yq = map(float, input().split(','))
    except EOFError :
        break
    
    if x1 != x2 and y1 != y2:
        ## d_P1_P2 : P1-P2の傾き ##
        d_P1_P2 = (y2-y1)/(x2-x1)
        ## d_Q1_Q2 : Q1-Q2の傾き ##
        d_Q1_Q2 = -1/d_P1_P2
        
        ## 直線P1-P2 ##
        b_P1_P2 = y1 - d_P1_P2 * x1
        ## y = d_P1_P2 * x + b_P1_P2
        
        ## 直線Q1-Q2 ##
        b_Q1_Q2 = yq - d_Q1_Q2 * xq
        ## y = d_Q1_Q2 * x + b_Q1_Q2
        
        ## P1-P2 と Q1-Q2 の交点(xq3, yq3) ##
        ## d_P1_P2 * x + b_P1_P2 = d_Q1_Q2 * x + b_Q1_Q2
        ## (d_P1_P2 - d_Q1_Q2) * x = b_Q1_Q2 - b_P1_P2
        xq3 = (b_Q1_Q2 - b_P1_P2) / (d_P1_P2 - d_Q1_Q2)
        yq3 = d_P1_P2 * xq3 + b_P1_P2
        
        ## Q2の座標(xq2, yq2) ##
        xq2 = xq3 - (xq - xq3)
        yq2 = yq3 - (yq - yq3)
        
    elif x1 == x2 :
        xq2 = x1 + x1 - xq
        yq2 = yq
    
    else :
        xq2 = xq
        yq2 = y1 - (yq - y1)
    
    print('{0:.8f} {1:.8f}'.format(xq2, yq2))

Submission status: Accepted

Solution code:
class Point(object):
    __slots__ = ["x", "y"]

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __iter__(self):
        yield self.x
        yield self.y

    def __add__(self, other: "Point") -> "Point":
        return Point(self.x + other.x, self.y + other.y)

    def __sub__(self, other: "Point") -> "Point":
        return Point(self.x - other.x, self.y - other.y)

    def __mul__(self, s: int):
        return Point(self.x * s, self.y * s)

    def project(self, vector: "Vector") -> "Point":
        return (vector * (Vector(vector.p1, self).dot(vector) / vector.norm)).p2

    def reflect(self, vector: "Vector") -> "Point":
        return self + (self.project(vector) - self) * 2


class Vector(object):
    __slots__ = ["p1", "p2", "x", "y", "norm", "abs"]

    def __init__(self, p1: Point, p2: Point):
        self.p1 = p1
        self.p2 = p2
        self.x = p2.x - p1.x
        self.y = p2.y - p1.y
        self.norm = self.x ** 2 + self.y ** 2
        self.abs = abs(self.x + self.y)

    def __mul__(self, s):
        return Vector(self.p1, Point(self.p1.x + self.x * s, self.p1.y + self.y * s))

    def __lt__(self, other: "Vector"):
        return other.abs > self.abs

    def __gt__(self, other: "Vector"):
        return other.abs < self.abs

    def dot(self, other: "Vector"):
        return self.x * other.x + self.y * other.y

    def cross(self, other: "Vector"):
        return self.x * other.y - self.y * other.x


if __name__ == "__main__":
    import sys
    for x1, y1, x2, y2, xq, yq in (map(float, l.split(",")) for l in sys.stdin):
        vector = Vector(Point(x1, y1), Point(x2, y2))
        print(*Point(xq, yq).reflect(vector))

Submission status: Accepted

Solution code:
from math import sqrt,atan2,cos,sin
while(1):
    try:
        x1,y1,x2,y2,xq,yq = [float(i) for i in input().split(",")]
        r = sqrt((xq-x1)**2 + (yq-y1)**2)
        th1 = atan2(y2-y1,x2-x1)
        th2 = atan2(yq-y1,xq-x1)
        th3 = -(th2 - th1) + th1
        print("{:.6f} {:.6f}".format(x1+r*cos(th3),y1+r*sin(th3)))
    except EOFError:
        break

Submission status: Accepted

Solution code:
try:
    while True:
        T = tuple(map(float,input().strip().split(",")))
        z = complex(T[0]-T[2],T[1]-T[3])
        P = complex(T[0],T[1])
        Q = complex(T[4],T[5])
        R = P + (Q-P).conjugate() * z / z.conjugate()
        print("%.6f %.6f" % (R.real,R.imag))
except EOFError:
    pass

Submission status: Runtime Error

Solution code:
import sys
from math import complex as C
for e in sys.stdin:
 a,b,c,d,e,f=map(float,e.split(','))
 z,w,q=C(a,b),C(c,d),C(e,f)
 w-=z
 z+=(w/abs(w))**2*(q-z).conjugate()
 print(z.real,z.imag)

Submission status: Runtime Error

Solution code:
import sys,math
for line in sys.stdin.readlines():
    line=raw_input()
    x1,y1,x2,y2,xq,yq=map(float,line.strip().split(","))
    L=((x1-x2)**2+(y1-y2)**2)**0.5
    t=math.atan2(y2-y1,x2-x1)
    R1=((x1-xq)**2+(y1-yq)**2)**0.5
    R2=((x2-xq)**2+(y2-yq)**2)**0.5
    a=math.acos((L*L+R1*R1-R2*R2)/(2*L*R1))
    x,y=x1+R1*math.cos(t+a),y1+R1*math.sin(t+a)
    if not (xq-0.00001<=x<=xq+0.00001 and yq-0.00001<=y<=yq+0.00001):
        print x,y
    else:
        print x1+R1*math.cos(t-a),y1+R1*math.sin(t-a)
#temp

Submission status: Runtime Error

Solution code:
import sys
for line in sys.stdin.readlines():
    x1,y1,x2,y2,xq,yq=map(float,line.strip().split(","))
    if x1==x2:
        x,y=-xq+2*x1,yq
    elif y1==y2:
        x,y=xq,-yq+2*y1
    else:
        m=(y1-y2)/(x1-x2)
        n=-m*x1+y1
        x,y= (2*yq*m-2*m*n+xq-m*m*xq)/(m*m+1),(xq-x)/m+yq;
    print "{:.6f} {:.6f}".format(x+0,y+0)