SlideShare a Scribd company logo
1 of 11
Download to read offline
!
~ ~
!
2 !
!
2 !
1 !
2
p r !
typedef pair<P, double> C;!
!
= 2r, = 2"r, = "r2!
2 : dis(pa,pb) ≦ ra+rb
p
r
2
int cpr(C a, C b){!
double d = abs(a.fs - b.fs);!
if(a.sc+b.sc + EPS < d)return -1; //0 cp (outside)!
if(b.sc+d + EPS < a.sc) return 1; //0 cp (B in A)!
if(a.sc+d + EPS < b.sc)return 2; //0 cp (A in B)!
if(abs(a.sc+b.sc - d) < EPS)return -3; //1 cp (outside)!
if(abs(a.sc+d - a.sc) < EPS)return 3; //1 cp (B in A)!
if(abs(a.sc+d - b.sc) < EPS)return 4; //1 cp (A in B)!
return 0; //2 cp!
}
3 a,b,c a (rad) ( )!
double arg(double a, double b, double c){!
return acos( (b*b+c*c - a*a)/(2*b*c) );!
}!
v s (rad)
( )!
P rotate(P v, double s){!
return P(v.real()*cos(s) - v.imag()*sin(s),!
v.real()*sin(s) + v.imag()*cos(s) );!
}
2
vector<P> CircleCrossPoint(C a, C b){!
vector<P> res;!
P x = a.sc * unit(b.fs - a.fs);!
if(cpr(a,b) >= 3){!
res.push_back(a.fs + x);!
}else if(cpr(a,b) == 0){!
double s = arg(b.sc, abs(b.fs-a.fs), a.sc);!
res.push_back(a.fs + rotate(x, s));!
res.push_back(a.fs + rotate(x,-s));!
}!
return res;!
}
s
x
a
b
vector<P> cpCircleLine(C a, L x){!
vector<P> res;!
P n = normal(x.fs-x.sc).fs;!
P p = line_cp(x, L(a.fs,a.fs+n));!
if(abs(abs(a.fs-p) - d)<EPS){!
res.push_back(p);!
}else if(abs(a.fs-p)+EPS<d){!
D len = sqrt(a.sc*a.sc - norm(a.fs-p));!
P cp = len * unit(x.fs - x.sc);!
res.push_back(p + cp);!
res.push_back(p - cp);!
}!
return res;!
}
n a
x
p
2
vector<P> CircleCrossPoint(C a, C b){!
double d = abs(a.fs - b.fs);!
if(a.sc + b.sc < d+EPS)return 0;!
if(a.sc < b.sc)swap(a,b);!
if(b.sc + d < a.sc + EPS)return area(b);!
!
double s1 = arg(b.sc,a.sc,d), s2 = arg(a.sc,b.sc,d);!
double tri = (a.sc*a.sc*sin(s1*2) + b.sc*b.sc*sin(s2*2) )/2;!
return a.sc*a.sc*s1 + b.sc*b.sc*s2 - tri;!
}
s1
d
a
b
1
c
p
vector<L> TangentLine(C c, P p){!
vector<L> res;!
P a = c.fs + c.sc * unit(p - c.fs);!
vector<P> b = cpCircleLine( C(c.fs, abs(c.fs-p), L(a,a+normal(c.fs-p).fs) );!
for(int i=0;i<b.size();i++){!
res.push_back( L(p, c.fs + c.sc*unit(b[i] - c.fs)) );!
}!
return res;!
}
a
2
a
b
vector<L> CommonTangentLine(C a, C b){!
vector<L> res;!
if(a.sc+EPS < b.sc)swap(a,b);!
if(a == b)return res; // !
P p = (b.fs-a.fs)*a.sc / (a.sc+b.sc) + a.fs;!
if(abs(a-p)+EPS>a.sc)res = AjacentLine(a,p);!
......
p
v
2
a
b
vector<L> CommonTangentLine(C a, C b){!
......!
if(abs(a.sc-b.sc) < EPS){!
pair<P,P> n = normal(unit(b.fs-a.fs)*a.sc);!
res.push_back(L(a.fs+n.fs, b.fs+n.fs));!
res.push_back(L(a.fs+n.sc, b.fs+n.sc));!
}else{

P p = (b.fs-a.fs) * a.sc/(a.sc-b.sc) + a.fs;!
if(abs(a-p)+EPS>a.sc){!
vector<L> tmp = AdjacentLine(a,p);!
for(int i=0;i<tmp.size();i++)res.push_back(tmp[i]);!
}!
}!
return res;!
}
v
p

More Related Content

What's hot

Engineer event in Kyoto 10-04-17
Engineer event in Kyoto 10-04-17Engineer event in Kyoto 10-04-17
Engineer event in Kyoto 10-04-17ryo katsuma
 
Jillians Potw
Jillians PotwJillians Potw
Jillians Potwsabsma
 
Jillian Fluet’S Potw Solution
Jillian Fluet’S Potw SolutionJillian Fluet’S Potw Solution
Jillian Fluet’S Potw Solutionjillianfluet
 
Closest point on OBB to point by j3j3bu5t3r5
Closest point on OBB to point by j3j3bu5t3r5Closest point on OBB to point by j3j3bu5t3r5
Closest point on OBB to point by j3j3bu5t3r5gsantos15
 
Efficient Random-Walk Methods forApproximating Polytope Volume
Efficient Random-Walk Methods forApproximating Polytope VolumeEfficient Random-Walk Methods forApproximating Polytope Volume
Efficient Random-Walk Methods forApproximating Polytope VolumeVissarion Fisikopoulos
 
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Gaya horizontal pada tiang pancang
Gaya horizontal pada tiang pancangGaya horizontal pada tiang pancang
Gaya horizontal pada tiang pancangNurul Angreliany
 
Gssl
GsslGssl
Gsslncct
 

What's hot (14)

Engineer event in Kyoto 10-04-17
Engineer event in Kyoto 10-04-17Engineer event in Kyoto 10-04-17
Engineer event in Kyoto 10-04-17
 
Prgišče Lispa
Prgišče LispaPrgišče Lispa
Prgišče Lispa
 
Jillians Potw
Jillians PotwJillians Potw
Jillians Potw
 
Jillian Fluet’S Potw Solution
Jillian Fluet’S Potw SolutionJillian Fluet’S Potw Solution
Jillian Fluet’S Potw Solution
 
3
33
3
 
Afshaa fybca1
Afshaa fybca1Afshaa fybca1
Afshaa fybca1
 
Closest point on OBB to point by j3j3bu5t3r5
Closest point on OBB to point by j3j3bu5t3r5Closest point on OBB to point by j3j3bu5t3r5
Closest point on OBB to point by j3j3bu5t3r5
 
6 pointers functions
6 pointers functions6 pointers functions
6 pointers functions
 
Strongly Connected Components
Strongly Connected Components Strongly Connected Components
Strongly Connected Components
 
Efficient Random-Walk Methods forApproximating Polytope Volume
Efficient Random-Walk Methods forApproximating Polytope VolumeEfficient Random-Walk Methods forApproximating Polytope Volume
Efficient Random-Walk Methods forApproximating Polytope Volume
 
Fuvest 2017 - aberta
Fuvest 2017 - abertaFuvest 2017 - aberta
Fuvest 2017 - aberta
 
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
 
Gaya horizontal pada tiang pancang
Gaya horizontal pada tiang pancangGaya horizontal pada tiang pancang
Gaya horizontal pada tiang pancang
 
Gssl
GsslGssl
Gssl
 

Similar to Kika2

String Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmString Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmKiran K
 
Laplace1 8merged
Laplace1 8mergedLaplace1 8merged
Laplace1 8mergedcohtran
 
Globant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional ProgramingGlobant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional ProgramingGlobant
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 

Similar to Kika2 (10)

String Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmString Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
 
6. binary tree
6. binary tree6. binary tree
6. binary tree
 
Hendromardikadorkdanbretastevanny.js
Hendromardikadorkdanbretastevanny.jsHendromardikadorkdanbretastevanny.js
Hendromardikadorkdanbretastevanny.js
 
Maths formulae
Maths formulaeMaths formulae
Maths formulae
 
Laplace1 8merged
Laplace1 8mergedLaplace1 8merged
Laplace1 8merged
 
Globant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional ProgramingGlobant development week / Lamda & Functional Programing
Globant development week / Lamda & Functional Programing
 
Combinator parsing
Combinator parsingCombinator parsing
Combinator parsing
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
D1
D1D1
D1
 

More from HCPC: 北海道大学競技プログラミングサークル

More from HCPC: 北海道大学競技プログラミングサークル (20)

写像 12 相
写像 12 相写像 12 相
写像 12 相
 
ACPC 2017 Day3 F: 掛け算は楽しい
ACPC 2017 Day3 F: 掛け算は楽しいACPC 2017 Day3 F: 掛け算は楽しい
ACPC 2017 Day3 F: 掛け算は楽しい
 
ACPC 2017 Day3 D: 優柔不断
ACPC 2017 Day3 D: 優柔不断ACPC 2017 Day3 D: 優柔不断
ACPC 2017 Day3 D: 優柔不断
 
ACPC 2019 Day3 G: Restricted DFS
ACPC 2019 Day3 G: Restricted DFSACPC 2019 Day3 G: Restricted DFS
ACPC 2019 Day3 G: Restricted DFS
 
ACPC 2019 Day3 F: 部分文字列分解
ACPC 2019 Day3 F: 部分文字列分解ACPC 2019 Day3 F: 部分文字列分解
ACPC 2019 Day3 F: 部分文字列分解
 
ACPC 2019 Day3 E: 総和の切り取り
ACPC 2019 Day3 E: 総和の切り取りACPC 2019 Day3 E: 総和の切り取り
ACPC 2019 Day3 E: 総和の切り取り
 
ACPC 2019 Day3 B: パフェ
ACPC 2019 Day3 B: パフェACPC 2019 Day3 B: パフェ
ACPC 2019 Day3 B: パフェ
 
ACPC 2019 Day3 A: 間違い探し
ACPC 2019 Day3 A: 間違い探しACPC 2019 Day3 A: 間違い探し
ACPC 2019 Day3 A: 間違い探し
 
HUPC 2019 Day2 G: 木
HUPC 2019 Day2 G: 木HUPC 2019 Day2 G: 木
HUPC 2019 Day2 G: 木
 
HUPC 2019 Day2 E: ジャム
HUPC 2019 Day2 E: ジャムHUPC 2019 Day2 E: ジャム
HUPC 2019 Day2 E: ジャム
 
HUPC 2019 Day2 H: Revenge of UMG
HUPC 2019 Day2 H: Revenge of UMGHUPC 2019 Day2 H: Revenge of UMG
HUPC 2019 Day2 H: Revenge of UMG
 
HUPC 2019 Day2 F: MOD Rush
HUPC 2019 Day2 F: MOD RushHUPC 2019 Day2 F: MOD Rush
HUPC 2019 Day2 F: MOD Rush
 
HUPC 2019 Day2 C: 串刺し
HUPC 2019 Day2 C: 串刺しHUPC 2019 Day2 C: 串刺し
HUPC 2019 Day2 C: 串刺し
 
HUPC 2019 Day1 F: グリッドの番号
HUPC 2019 Day1 F: グリッドの番号HUPC 2019 Day1 F: グリッドの番号
HUPC 2019 Day1 F: グリッドの番号
 
HUPC 2019 Day1 E: 最短経路の復元
HUPC 2019 Day1 E: 最短経路の復元HUPC 2019 Day1 E: 最短経路の復元
HUPC 2019 Day1 E: 最短経路の復元
 
HUPC 2019 Day1 D: 貪欲が最適?
HUPC 2019 Day1 D: 貪欲が最適?HUPC 2019 Day1 D: 貪欲が最適?
HUPC 2019 Day1 D: 貪欲が最適?
 
HUPC 2019 Day1 C: 短絡評価
HUPC 2019 Day1 C: 短絡評価HUPC 2019 Day1 C: 短絡評価
HUPC 2019 Day1 C: 短絡評価
 
HUPC 2019 Day1 B: 自身の 2 倍
HUPC 2019 Day1 B: 自身の 2 倍HUPC 2019 Day1 B: 自身の 2 倍
HUPC 2019 Day1 B: 自身の 2 倍
 
HUPC 2019 Day1 A: four tea
HUPC 2019 Day1 A: four teaHUPC 2019 Day1 A: four tea
HUPC 2019 Day1 A: four tea
 
Convex Hull Trick
Convex Hull TrickConvex Hull Trick
Convex Hull Trick
 

Recently uploaded

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Recently uploaded (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Kika2

  • 3. p r ! typedef pair<P, double> C;! ! = 2r, = 2"r, = "r2! 2 : dis(pa,pb) ≦ ra+rb p r
  • 4. 2 int cpr(C a, C b){! double d = abs(a.fs - b.fs);! if(a.sc+b.sc + EPS < d)return -1; //0 cp (outside)! if(b.sc+d + EPS < a.sc) return 1; //0 cp (B in A)! if(a.sc+d + EPS < b.sc)return 2; //0 cp (A in B)! if(abs(a.sc+b.sc - d) < EPS)return -3; //1 cp (outside)! if(abs(a.sc+d - a.sc) < EPS)return 3; //1 cp (B in A)! if(abs(a.sc+d - b.sc) < EPS)return 4; //1 cp (A in B)! return 0; //2 cp! }
  • 5. 3 a,b,c a (rad) ( )! double arg(double a, double b, double c){! return acos( (b*b+c*c - a*a)/(2*b*c) );! }! v s (rad) ( )! P rotate(P v, double s){! return P(v.real()*cos(s) - v.imag()*sin(s),! v.real()*sin(s) + v.imag()*cos(s) );! }
  • 6. 2 vector<P> CircleCrossPoint(C a, C b){! vector<P> res;! P x = a.sc * unit(b.fs - a.fs);! if(cpr(a,b) >= 3){! res.push_back(a.fs + x);! }else if(cpr(a,b) == 0){! double s = arg(b.sc, abs(b.fs-a.fs), a.sc);! res.push_back(a.fs + rotate(x, s));! res.push_back(a.fs + rotate(x,-s));! }! return res;! } s x a b
  • 7. vector<P> cpCircleLine(C a, L x){! vector<P> res;! P n = normal(x.fs-x.sc).fs;! P p = line_cp(x, L(a.fs,a.fs+n));! if(abs(abs(a.fs-p) - d)<EPS){! res.push_back(p);! }else if(abs(a.fs-p)+EPS<d){! D len = sqrt(a.sc*a.sc - norm(a.fs-p));! P cp = len * unit(x.fs - x.sc);! res.push_back(p + cp);! res.push_back(p - cp);! }! return res;! } n a x p
  • 8. 2 vector<P> CircleCrossPoint(C a, C b){! double d = abs(a.fs - b.fs);! if(a.sc + b.sc < d+EPS)return 0;! if(a.sc < b.sc)swap(a,b);! if(b.sc + d < a.sc + EPS)return area(b);! ! double s1 = arg(b.sc,a.sc,d), s2 = arg(a.sc,b.sc,d);! double tri = (a.sc*a.sc*sin(s1*2) + b.sc*b.sc*sin(s2*2) )/2;! return a.sc*a.sc*s1 + b.sc*b.sc*s2 - tri;! } s1 d a b
  • 9. 1 c p vector<L> TangentLine(C c, P p){! vector<L> res;! P a = c.fs + c.sc * unit(p - c.fs);! vector<P> b = cpCircleLine( C(c.fs, abs(c.fs-p), L(a,a+normal(c.fs-p).fs) );! for(int i=0;i<b.size();i++){! res.push_back( L(p, c.fs + c.sc*unit(b[i] - c.fs)) );! }! return res;! } a
  • 10. 2 a b vector<L> CommonTangentLine(C a, C b){! vector<L> res;! if(a.sc+EPS < b.sc)swap(a,b);! if(a == b)return res; // ! P p = (b.fs-a.fs)*a.sc / (a.sc+b.sc) + a.fs;! if(abs(a-p)+EPS>a.sc)res = AjacentLine(a,p);! ...... p v
  • 11. 2 a b vector<L> CommonTangentLine(C a, C b){! ......! if(abs(a.sc-b.sc) < EPS){! pair<P,P> n = normal(unit(b.fs-a.fs)*a.sc);! res.push_back(L(a.fs+n.fs, b.fs+n.fs));! res.push_back(L(a.fs+n.sc, b.fs+n.sc));! }else{
 P p = (b.fs-a.fs) * a.sc/(a.sc-b.sc) + a.fs;! if(abs(a-p)+EPS>a.sc){! vector<L> tmp = AdjacentLine(a,p);! for(int i=0;i<tmp.size();i++)res.push_back(tmp[i]);! }! }! return res;! } v p