1. 程式人生 > >Miracles happen every day.

Miracles happen every day.

兩圓相交分如下集中情況:相離、相切、相交、包含。

設兩圓圓心分別是O1和O2,半徑分別是r1和r2,設d為兩圓心距離。又因為兩圓有大有小,我們設較小的圓是O1

相離相切的面積為零,程式碼如下:

double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
if (d >= r1+r2)
	return 0;
包含的面積就是小圓的面積了,程式碼如下:
if(r2 - r1 >= d)
	return pi*r1*r1;
接下來看看相交的情況。


相交面積可以這樣算:扇形O1AB - △O1AB + 扇形O2AB - △O2AB,這兩個三角形組成了一個四邊形,可以用兩倍的△O1AO2求得,

所以答案就是兩個扇形-兩倍的△O1AO2


因為

所以

那麼

同理

接下來是四邊形面積:

程式碼如下:

double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));
return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
至此完整程式碼就可以寫出來了:
#include<iostream>
#include<cmath>
using namespace std;

#define pi acos(-1.0)

typedef struct node
{
	int x;
	int y;
}point;

double AREA(point a, double r1, point b, double r2)
{
	double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
	if (d >= r1+r2)
		return 0;
	if (r1>r2)
	{
		double tmp = r1;
		r1 = r2;
		r2 = tmp;
	}
	if(r2 - r1 >= d)
		return pi*r1*r1;
	double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
	double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));
	return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
}

int main()
{
	point a, b;
	a.x=2, a.y=2;
	b.x=7, b.y=2;
	double result = AREA(a, 3, b, 5);
	printf("%lf\n", result);
	return 0;
}


相關推薦

Miracles happen every day.

兩圓相交分如下集中情況:相離、相切、相交、包含。 設兩圓圓心分別是O1和O2,半徑分別是r1和r2,設d為兩圓心距離。又因為兩圓有大有小,我們設較小的圓是O1。 相離相切的面積為零,程式碼如下: double d = sqrt((a.x-b.x)*(a.x-b.x) +

Learn a linux command every day--day1:cd命令

new peid nbsp 進行 所在 test 執行 環境變量 inux Linux cd 命令可以說是Linux中最基本的命令語句,用於切換目錄,是shell的內置命令,要進行其他操作,都是建立在使用 cd 命令上的。 所以,學習Linux 常用命令,首先就要學好 cd

【英語】A positive view of every day

If your life feels like it is lacking the power that you want and the motivation that you need, sometimes all you have to do is shift your point

every day a practice —— morning

In 25 years, Panda Express has transformed from a single restaurant in a southern California mall to a 2000-location empire around the world. &n

every day a practice —— morning(2)

Two years at sea have fostered a close relationship between the two fellow sailors as they cross the globe, through warm weather and cold. 兩年的環球航海生活,

every day a practice —— morning(3)

"WeChat does not store any chat histories. They are stored only on users' phones, computers or other devices," Tencent said in a statement on its own WeCha

every day a practice —— morning(4)

If there’s one thing New Yorkers love more than discovering a new secret remedy, it’s telling other New Yorkers about it.與發現新的祕方相比,紐約人更熱衷的事情是去和其他人分享祕方。 &n

every day a practice —— morning(5)

Huawei has not been accused of wrongdoing. As an administrative subpoena, the Treasury document does not indicate that the Chinese company is part of

every day a practice —— morning(7)

It is probably because Willow was the last link to her parents and a pastime that goes back to her own childhood. It really does feel like the end of an er

Ask HN: What do you do to improve every day?

I've often heard/read that one should aim to improve themselves a little bit each day (e.g. improve by 1%, whatever that means, every day and your progress

6 Alexa skills you'll use every day

Alexa is no longer "new." The smart-tech revolution is now in full swing, and Amazon Echo is at the heart of it. According to Edison Research, nearly 40 mi

Novel machine learning technique for simulating the every day task of dressing

Computer scientists from the Georgia Institute of Technology and Google Brain, Google's artificial intelligence research arm, have devised a novel computa

“糞便銀行”:救人拿錢兩不誤 A Poop Bank in Massachusetts Will Pay You $40 Every Day

“糞便銀行”:救人拿錢兩不誤 如果你年齡小於50歲,排便規律,而且願意每天去美國麻省麥德福德跑一趟,那麼沒準你可以每天得到40美元的外快,而你需要做的事情只是生產便便。  要想得到這筆收入,請拜訪“開放生物群”(OpenBiome)。它是全美唯一的獨立非營利性“糞便銀行”,初建於2012年,由麻省理工學

a little progress every day

1,按鈕 此類建立一個標籤按鈕。當按下該按鈕時,應用程式能執行某項動作。它有兩種構造方法: public Button() 構造一個標籤字串為空的按鈕。 public Button(String label)

IOS study every day

The choice of control content scripts is above UISegmentedControl, the general application scenario is basically the function of class  

Python First Day

代碼 python解釋器 石家莊 erp image 內存 als pan mov A. python介紹 - 可以減少開發成本,代碼開源 - 運行速度慢 B. python和其它語言對比 - C語言 : 編譯 -> 機器碼 -> 計算機 -

day 2 基本類型和函數

索引 如果 重復 是不是 特定 enc cti 復用 增加 列表,元組,字典的轉換。 list列表是一組可變的元素集合 列表是‘[]‘括號組成的,[]括號包含所有元素,列表的創建可以傳遞字符串,也可以傳遞多個字符串來創建列表。如"asd", / "a","b" ...

NOIP2012提高組 Day 2 Problem 2 借教室

修改 () else 時間復雜度 希望 logs 樸素 main 差分 原題 題目描述 在大學期間,經常需要租借教室。大到院系舉辦活動,小到學習小組自習討論,都需要向學校申請借教室。教室的大小功能不同,借教室人的身份不同,借教室的手續也不一樣。 面對海量租借教室的信息,我

[uvalive 7263] Today Is a Rainy Day(暴力,BFS,dp)

預處理 ini pen sta 現在 修改 ace printf main 題目鏈接:https://vjudge.net/problem/UVALive-7263 題意:給兩個字符串a,b,只包含1~6的數字,現在允許兩種操作:1、修改某一位數字,2、修改整個串的某個數字

Day 2 操作系統基礎

競爭 多路復用 disk 導圖 cnblogs img 代碼 depend strong 課前復習新知識 RAID(Redundant Arrays of Independent Disks)獨立冗余磁盤陣列   定義:加州大學伯克利分校1987年提出,最初是為了組合小的廉