學習筆記 計算幾何

2022-09-19 11:18:13 字數 1809 閱讀 1099

高中數學必修二內容,基本理論見 oiwiki。

先上**:

struct node

node(double _x,double _y)

void input()

node friend operator+(node a,node b)

double friend operator*(node a,node b)//點積

double friend operator^(node a,node b)//叉積

void rot(double a)

};

根據向量的座標表示,可以用 \((x,y)\) 來表示乙個向量。

struct node

node(double _x,double _y)

void input()

};

由於我們用座標表示乙個向量,那麼兩個向量相加減實際上就是對應座標的加減。

node friend operator+(node a,node b)

node friend operator-(node a,node b)

我們都知道 \(\vec\cdot\vec=|\vec||\vec|\cos\theta\)。其中 \(|\vec|=\sqrt\),\(|\vec|=\sqrt\),然後根據餘弦定理:\(d_^2=|\vec|^2+|\vec|^2-2|\vec||\vec|\cos\theta=(x_a-x_b)^2+(y_a-y_b)^2\),可以得到:\(-2|\vec||\vec|\cos\theta=-2x_ax_b-2y_ay_b\) 即 \(|\vec||\vec|\cos\theta=x_ax_b+y_ay_b\)。

所以 \(\vec\cdot\vec=x_ax_b+y_ay_b\)。

double friend operator*(node a,node b)
我們都知道 \(|\vec\times\vec|=|\vec||\vec|\sin\theta\)。

我們都知道叉積有幾何意義就是兩條向量圍成的三角形面積的兩倍。

看張圖,可以發現所謂三角形面積的兩倍就是圖中黃色的面積。而黃色的面積就是 \(x_by_a-x_ay_b\),由於 \(\vec\times\vec\) 的結果根據右手螺旋定則是負的,所以叉積的表示式就是 \(|\vec\times\vec|=x_ay_b-x_by_a\)。

叉積的用處還是非常多的。

double friend operator^(node a,node b)
嫖一張圖:

展開得:

\[\vec=(l(\cos\theta\cos\alpha-\sin\theta\sin\alpha),l(\sin\theta\cos\alpha+\cos\theta\sin\alpha))

\]\[=(l\cos\theta\cos\alpha-l\sin\theta\sin\alpha,l\sin\theta\cos\alpha+l\cos\theta\sin\alpha)

\]\[=(x\cos\alpha-y\sin\alpha,y\cos\alpha+x\sin\alpha)

\]

void rot(double a)
先上**:

struct line

line(node _s,node _e)

}

計算幾何學習筆記

基礎部分 include using namespace std define type double define vector point define eps 1e 8 const double pi 3.14159265358979323 type deg2red type deg type...

計算幾何學習筆記

計算幾何是什麼東西?能吃嗎?給定 n 個點 x i,yi 問 歐幾里得 距離最近的點對。如果用樸素的兩兩枚舉,需要o n2 的時間。考慮用分治法,先將點按照先 x 後 y排序。考慮對一段點 l r 的處理。在 放一根平行於y軸的線,其左邊的答案為a,右邊為b,設 min a,b 考慮如果有跨這條線的...

學習筆記 立體計算幾何

基本知識 向量運算 模長 len x2 y2 z 2len sqrt len x2 y2 z2 加減 對應座標加減,結果為乙個向量 點積 依舊定義為a vec a到b vec b的投影,計算方式為將對應座標相乘後相加,結果為乙個值。如 x1 y1,z1 x2,y2,z 2 x 1x2 y1y2 z1...