三点共线的判断,以及求已知三点的外接圆圆心
程序员文章站
2022-04-04 08:30:38
...
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define INF 0x3f3f3f
#define fi first
#define se second
#define it iterator
#define ins insert
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define np next_permutation
#define pq priority_queue
#define ll long long
#define ull unsigned long long
#define mem(a,x) memset(a,x,sizeof(a))
#define cio ios::sync_with_stdio(false) // 不能和C的输入混用
inline ll gcd(ll a,ll b){return b == 0? a:gcd(b, a % b);}
inline int lowbit(int x){return x&(-x);}
#define S(n) setiosflags(ios::fixed) << setprecision(n)
#define T int t;scanf("%d",&t);while(t--)
#define Ce cout << endl
#define C(n,m) cout << S(n) << m << endl
#define CY cout << "YES" << endl
#define CN cout << "NO" << endl
#define Cy cout << "Yes" << endl
#define Cn cout << "No" << endl
int main ()
{
double x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
if((x1*y2-x2*y1)+(x2*y3-x3*y2)+(x3*y1-y3*x1)==0)
{
cout << "三点共线" << endl;
exit(0);
}
// Ax^2+Ay^2+Bx+Cy+D = 0 圆方程
double A = x1*(y2-y3)-y1*(x2-x3)+x2*y3-x3*y2;
double B = (x1*x1+y1*y1)*(y3-y2)+(x2*x2+y2*y2)*(y1-y3)+(x3*x3+y3*y3)*(y2-y1);
double C = (x1*x1+y1*y1)*(x2-x3)+(x2*x2+y2*y2)*(x3-x1)+(x3*x3+y3*y3)*(x1-x2);
double X = -B/(2*A);
double Y = -C/(2*A);
cout << "圆心坐标为:(" << S(2) << X << "," << S(2) << Y << endl;
return 0;
}