拋物線頂點方程式
y = a(x-h)^2 + k
代入
=> y = a(x - x1)^2 + y1
a = (y2-y1)/(x2-x1)^2
=> (x2 - x1)^2 y = (y2 - y1)(x - x1)^2 + y1
(x2 - x1)^2 y = (y2 - y1)x^2 - 2x1(y2 - y1)x + (y2 - y1)x1^2 + y1
迴圈
輸入x1 y1 x2 y2
計算係數
約分
輸出
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int x1, x2, y1, y2;
int a, b, c, d, gcd;
while(cin >> x1 >> y1 >> x2 >> y2)
{
a = (x2-x1)*(x2-x1);
b = y2-y1;
c = -2*x1*(y2-y1);
d = (y2-y1)*x1*x1 + y1*(x2-x1)*(x2-x1);
gcd = __gcd(a, b), gcd = __gcd(gcd, c), gcd = __gcd(gcd, d);
cout << a/gcd << "y = " << b/gcd << "x^2 + " << c/gcd << "x + " << d/gcd << endl;
}
return 0;
}
留言列表