日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

已知圆上两点坐标和半径求圆心

發(fā)布時(shí)間:2023/12/20 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 已知圆上两点坐标和半径求圆心 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

牛客題目鏈接

已知兩點(diǎn)坐標(biāo)可求出直線方程,當(dāng)然也包括斜率了,已知斜率tan a,最近剛學(xué)的高數(shù)上,可根據(jù)三角函數(shù)的反函數(shù)(C++ atan2(y,x))求出角度(小心為double類型),用到圓心到兩點(diǎn)中點(diǎn)這條邊可求出圓心。

/**遇到此類型的題目就是先確定圓心再去判斷其他店是否在圓上或者圓內(nèi)**/#include <map> #include <queue> #include <string> #include<iostream> #include<stdio.h> #include<string.h> #include <algorithm> #include <math.h> typedef long long ll; typedef unsigned long long ull; using namespace std; typedef pair<ll,ll> pii; const int maxn=2e5+1010; #define inf 0x3f3f3f3f #define sf scanf #define pf printf const int mod=998244353; const int MOD=10007; const double eps=1e-6;ll r,num;struct Point {double x,y;Point(){}Point(double tx,double ty){x=tx;y=ty;} }p[200];double dist(Point p1,Point p2) {return sqrt(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2));///求出兩點(diǎn)距離 }Point Center(Point p1,Point p2) {Point mid = Point((p1.x+p2.x)/2,(p1.y+p2.y)/2);///求得中點(diǎn)坐標(biāo)double angle = atan2(p1.x-p2.x,p2.y-p1.y); ///求出極坐標(biāo)double d = sqrt(r*r-pow(dist(p1,mid),2));///求出側(cè)邊也就是圓心到其中點(diǎn)的距離return Point(mid.x-d*cos(angle),mid.y-d*sin(angle));///求出圓心坐標(biāo) }int main() {cin>>r;cin>>num;for(int i=0;i<num;i++)cin>>p[i].x>>p[i].y;ll ans = 1;for(int i=0;i<num;i++){for(int j=i+1;j<num;j++){if(dist(p[i],p[j]) > 2.0*r) continue;///兩點(diǎn)距離比直徑大直接退出Point center = Center(p[i],p[j]);///求出圓心的ll cnt = 0;for(int k=0;k<num;k++)if(dist(center,p[k]) < 1.0*r+eps) cnt++;///求這個(gè)求出來的圓心點(diǎn)到個(gè)點(diǎn)的距離是否瞞住條件ans = max(ans,cnt);///求出最大值}}cout<<ans<<endl;return 0; }

總結(jié)

以上是生活随笔為你收集整理的已知圆上两点坐标和半径求圆心的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。