--- tags: Math, Vector Algebra title: Vector Alebra author: license: --- $\Huge \text{Vector Algebra}$ ---- :::info > 🔗 Link: > 📌 Tags: > 📋 Content: > [TOC] > > [color=blue] ::: --- --- --- --- --- ## <center> A. Giới thiệu </center> --- ### <center> A.1) Đối tượng độc giả </center> --- ### <center> A.2) Thông tin khác </center> --- --- --- --- --- ## <center> B. Không gian $\mathbb{R}^2$ </center> Kí hiệu $\mathbb{R}^2$ là tập hợp: $$ \mathbb{R}^2=\{\mathbf u=(x;y)\mid x,y\in\mathbb{R}\} $$ Khi đó $\mathbb{R}^2$ là không gian vector Mọi $u =(x; y) \in \mathbb{R}^2$ mô phỏng điểm $A(x; y)$ trên mặt phẳng $Oxy$ Để cho tiện, ta sẽ định nghĩa các biến sau > Góc degree giữa $2$ vector $\phi \in \mathbb{R}$ > Góc radian giữa $2$ vector $\theta \in \mathbb{R}$ > Đại số vô hướng $\alpha, \beta \in \mathbb{R}$ > Sai số $\varepsilon \in \mathbb{R}$ > Scalar $u_x, u_y, v_x, v_y, w_x, w_y \in \mathbb{R}$ > Vector $\mathbf u = (u_x; u_y), \mathbf v = (v_x; v_y), \mathbf w = (w_x; w_y) \in \mathbb{R}^2$ > [color=green] --- ### <center> B.1) Tính chất vector cơ bản </center> :::info **Definition**: $$ \text{vector }\mathbf u=(u_x;\ u_y)\in\mathbb{R}^2\\ \text{scalar }u_x, u_y \in \mathbb{R} $$ ::: > **Zero Vector**: $$ \mathbf0=(0;0)\\ \exists!\mathbf u=\mathbf 0\to\|\mathbf u\|=0 $$ > **Unit Vector**: $\forall\mathbf u\neq\mathbf 0$ $$ \widehat{\mathbf u} = (\sin(\theta);\ \cos(\theta)) = \frac{\mathbf u}{\|\mathbf u\|} $$ > **Basis Vector** $$ \mathbf i=\widehat{\mathbf i}=(1;0)\\ \mathbf j=\widehat{\mathbf j}=(0;1)\\ $$ > **Additive Identity**: $$ 0 + \mathbf{u} = \mathbf{u} + 0 = \mathbf{u} $$ > **Additive Inverse**: $$ \mathbf{u} + (-\mathbf{u}) = \mathbf{0} $$ > **Double Negation**: $$ -(-\mathbf{u}) = \mathbf u $$ > **Associativity**: $$ (\alpha\beta)\mathbf u=\alpha(\beta\mathbf u)=\beta(\alpha\mathbf u)\\ (\mathbf u\pm\mathbf v)\pm\mathbf w=\mathbf u\pm(\mathbf v\pm\mathbf w) $$ > **Commutativity**: $$ \mathbf u\pm\mathbf v = \mathbf v\pm\mathbf u\\ $$ > **Multiplicative Identity**: $$ \alpha \times \mathbf{u} = (\alpha u_x;\ \alpha u_y) $$ > **Distributivity**: $$ \alpha(\mathbf u\pm\mathbf v)=\alpha u\pm\alpha v\\ (\alpha\pm\beta)\mathbf u=\alpha\mathbf u\pm\beta\mathbf u $$ > > **Norm Property**: $$ \begin{cases} \|\mathbf u\|\geq0\\ \|\mathbf u\|=0\Leftrightarrow\mathbf u=\mathbf 0\\ \end{cases}\\ \begin{cases} \|\mathbf u-\mathbf v\|\geq0\\ \|\mathbf u-\mathbf v\|=0\Leftrightarrow\mathbf u=\mathbf v \end{cases}\\ $$ --- ### <center> B.2) Tính chất tích vô hướng (u⋅v) / tích chấm vuông (u⊥v) </center> :::info **Dot Product Definition**: $$ \mathbf u\cdot\mathbf v=u_x\times v_x+u_y\times v_y $$ **Perp Dot Product Definition**: $$ \mathbf u^{\perp}\cdot\mathbf v=u_xv_y-u_yv_x $$ **Perp Dot Relationship**: $$ perp_{2D}(\mathbf u, \mathbf v) = wedge_{2D}(\mathbf u, \mathbf v) = cross_{2D}(\mathbf u, \mathbf v)\\ $$ `Note:` Chỉ tồn tại ở không gian $2D$ ::: > **Nilpotent Property**: $$ 0 \cdot \mathbf{u} = \mathbf{u} \cdot 0 = 0\\ \mathbf u^{\perp}\cdot\mathbf u^{\perp}=0\\ $$ > **Squared Norm**: $$ \mathbf u\cdot\mathbf u=\|\mathbf u\|^2 $$ > **Associativity**: $$ \alpha(\mathbf u\cdot\mathbf v)=(\alpha\mathbf u)\cdot\mathbf v=\mathbf u\cdot(\alpha\mathbf v)\\ \alpha(\mathbf u^{\perp}\cdot\mathbf v)=(\alpha\mathbf u)^{\perp}\cdot\mathbf v=\mathbf u^{\perp}\cdot(\alpha\mathbf v) $$ > **Basis Vector**: $$ \widehat{\mathbf i}\cdot\widehat{\mathbf j}=0\\ \widehat{\mathbf i}^{\perp}\cdot\widehat{\mathbf j}=-1\\ $$ > **Commutativity**: $$ \mathbf u \cdot \mathbf v = \mathbf v \cdot \mathbf u\\ \mathbf u^{\perp} \cdot \mathbf v = \mathbf v \cdot \mathbf u^{\perp} $$ > **Anticommutativity**: $$ \mathbf u^{\perp}\cdot\mathbf v=-\mathbf v^{\perp}\cdot\mathbf u\\ $$ > **Multiplicative Distributivity**: $$ \mathbf u\cdot(\mathbf v\pm\mathbf w)=\mathbf u\cdot\mathbf v\pm\mathbf u\cdot\mathbf w\\ \mathbf u^{\perp}\cdot(\mathbf v\pm\mathbf w)=\mathbf u^{\perp}\cdot\mathbf v\pm\mathbf u^{\perp}\cdot\mathbf w\\ $$ > **Perpendicularity**: $$ \mathbf u\perp\mathbf v\Leftrightarrow\mathbf u\cdot\mathbf v=0 $$ > **Parallelity**: $$ \mathbf u\parallel\mathbf v\Leftrightarrow\mathbf u^{\perp}\cdot\mathbf v=0 $$ > **Squared Product**: $$ (\mathbf u\pm\mathbf v)\cdot(\mathbf u\pm\mathbf v)=(\mathbf u\cdot\mathbf u+\mathbf v\cdot\mathbf v)\pm2\mathbf u\mathbf v\\ (\mathbf u+\mathbf v)\cdot(\mathbf u-\mathbf v)=\mathbf u\cdot\mathbf u-\mathbf v\cdot\mathbf v $$ --- ### <center> B.3) Tính chất tích chéo (u×v) / tích ngoại (u∧v) </center> :::info **Cross Product Definition**: $$ cross_{3D}(\mathbf u, \mathbf v) = \mathbf u\times\mathbf v= \begin{pmatrix} u_yv_z - u_zv_y \\ u_zv_x - u_xv_z \\ u_xv_y - u_yv_x \\ \end{pmatrix}\\ cross_{2D}(\mathbf u, \mathbf v) = \|\mathbf u\times\mathbf v\|= (u_xv_y - u_yv_x)\widehat{\mathbf z} $$ **Wedge Product Definition**: $$ \mathbf u\wedge\mathbf v=\|\mathbf u\|\|\mathbf v\|\sin(\theta)\widehat{\mathbf n}\\ $$ **Cross Product Relationship** $$ wedge_{3D}(\mathbf u, \mathbf v) = cross_{3D}(\mathbf u, \mathbf v)\\ perp_{2D}(\mathbf u, \mathbf v) = wedge_{2D}(\mathbf u, \mathbf v) = cross_{2D}(\mathbf u, \mathbf v)\\ $$ **Note:** Ở không gian $2D$ và $3D$ thì tích chéo $\mathbf u\times\mathbf v$ cũng chính là tích ngoại $\mathbf u\wedge\mathbf v$ (nếu coi $e_1, e_2, e_3$ trực chuẩn nhau) **Note:** Tích chéo không tồn tại ở $1D$ và $4D$ trở lên vì không có khái niệm vector vuông góc duy nhất với mặt phẳng. ($1D$ thì không tồn tại, $4D$ thì không duy nhất). Tích ngoại có tồn tại nhưng ở không gian $1D$ thì khá vô nghĩa. $$ wedge_{1D}(\mathbf u, \mathbf v) = 0 $$ ::: > **Linearity**: $$ (\alpha\mathbf u+\beta\mathbf v)\wedge\mathbf w=\alpha(\mathbf u\wedge\mathbf w)+\beta(\mathbf v\wedge\mathbf w) $$ > **Multiplicative Identity**: $$ 1 \times \mathbf{u} = \mathbf{u} \times 1 = \mathbf{u}\\ $$ > **Nilpotent Property**: $$ 0 \times \mathbf{u} = \mathbf{u} \times 0 = 0\\ \mathbf u\times\mathbf u=0 $$ > **Associativity**: $$ \alpha(\mathbf u\times\mathbf v)=(\alpha\mathbf u)\times\mathbf v=\mathbf u\times(\alpha\mathbf v)\\ $$ > **Basis Vector** $$ \widehat{\mathbf i}\times\widehat{\mathbf j}=-1 $$ > **Anticommutativity**: $$ \mathbf u\times\mathbf v=-\mathbf v\times\mathbf u $$ > **Multiplicative Distributivity**: $$ \mathbf u\times(\mathbf v\pm\mathbf w)=(\mathbf u\times\mathbf v)\pm(\mathbf u\times\mathbf w) $$ --- ### <center> B.5) Tính chất tích hình học (uv) và [u,v] </center> :::info **Geometric Product Definition**: $$ \mathbf{uv}=\mathbf u\cdot\mathbf v + \mathbf u\wedge\mathbf v\\ $$ **Commutator Product Definition**: $$ \mathbf{vu} = [\mathbf u, \mathbf v] =\mathbf u\cdot\mathbf v - \mathbf u\wedge\mathbf v\\ $$ **Note**: Kết quả không phải là scalar hay vector, mà là một cặp scalar và bivector nên ta định nghĩa $$ \mathbf u\ \&\ \mathbf v = \text{vector2D}\left(\mathbf{uv};\ \mathbf{vu}\right) $$ ::: > **Symmetric**: $$ \mathbf u\cdot\mathbf v=\frac{1}{2}(\mathbf u\mathbf v+\mathbf v\mathbf u) $$ > **Antisymmetric**: $$ \mathbf u\wedge\mathbf v=\frac{1}{2}(\mathbf u\mathbf v-\mathbf v\mathbf u) $$ > **Associativity**: $$ (\mathbf u\mathbf v)\mathbf w=\mathbf u(\mathbf v\mathbf w) $$ > **Left Distributivity**: $$ \mathbf u(\mathbf v\pm\mathbf w)=\mathbf u\mathbf v\pm\mathbf u\mathbf w $$ > **Right Distributivity**: $$ (\mathbf u\pm\mathbf v)\mathbf w=\mathbf u\mathbf w+\mathbf v\mathbf w $$ > **Contraction**: $$ \mathbf u^2=\mathbf u\mathbf u=\|\mathbf u\|^2 $$ > **Inversion**: $$ \mathbf u^{-1}=\frac{\mathbf u}{\|\mathbf u\|^2} $$ > **Division**: $$ \frac{\mathbf u}{\mathbf v} = \frac{\mathbf u\mathbf v}{\|\mathbf v\|^2} $$ > **Identity**: $$ (\mathbf u\mathbf v+\mathbf v\mathbf u) = (\mathbf u+\mathbf v)^2-(\mathbf u^2+\mathbf v^2) $$ --- ### <center> B.6) Tính chất giữa các phép nhân </center> :::info $$ wedge_{3D}(\mathbf u, \mathbf v) = cross_{3D}(\mathbf u, \mathbf v)\\ perp_{2D}(\mathbf u, \mathbf v) = wedge_{2D}(\mathbf u, \mathbf v) = cross_{2D}(\mathbf u, \mathbf v)\\ $$ ::: > **Unit Vector**: $$ \underbrace{\|\widehat{\mathbf u}\times\widehat{\mathbf v}\|^2}_{\sin^2\theta}+\underbrace{(\widehat{\mathbf u}\cdot\widehat{\mathbf v})^2}_{\cos^2\theta}=\|\widehat{\mathbf u}\| = \|\widehat{\mathbf v}\| = 1\\ \widehat{\mathbf i}^{\perp}\cdot\widehat{\mathbf j}=\widehat{\mathbf i}\times\widehat{\mathbf j}=\left\|\widehat{\mathbf i}\times\widehat{\mathbf j}\right\|=-1\\ $$ > **Norm Property**: $$ \begin{cases} \|\mathbf u\times\mathbf v\|=\mathbf u^{\perp}\cdot\mathbf v=\|\mathbf u\|\|\mathbf v\|\sin\theta \geq 0\\ \|\mathbf u\times\mathbf v\|=0\Leftrightarrow\left[\begin{array}{l} \mathbf u=\mathbf 0\\ \mathbf v=\mathbf 0\\ \mathbf u\parallel\mathbf v \end{array}\right. \end{cases} $$ > **Jacobi Identity**: $$ \mathbf u\times(\mathbf v\times\mathbf w)+ \mathbf v\times(\mathbf w\times\mathbf u)+ \mathbf w\times(\mathbf u\times\mathbf v)= \mathbf 0 $$ > **Associativity/Scalar Triple Product**: $$ \mathbf u\cdot(\mathbf v\times\mathbf w)=\mathbf w\cdot(\mathbf u\times\mathbf v)=\mathbf v\cdot(\mathbf w\times\mathbf u) $$ > **Lagrange Identity**: $$ (\mathbf a\times\mathbf b)\cdot(\mathbf c\times\mathbf d)=(\mathbf a\cdot\mathbf c)(\mathbf b\cdot\mathbf d)-(\mathbf a\cdot\mathbf d)(\mathbf b\cdot\mathbf c)\\ \|\mathbf u^{\perp} \cdot \mathbf v\|^2=\|\mathbf u \times \mathbf v\|^2=\|\mathbf u\|^2\|\mathbf v\|^2-(\mathbf u\cdot\mathbf v)^2\\ $$ > **Product-Product Relation**: $$ \|\mathbf u\times\mathbf v\|=(\mathbf u^{\perp}\cdot\mathbf v)\widehat{\mathbf z}\\ \mathbf u\cdot\mathbf v=-\mathbf u^{\perp}\cdot\mathbf v^{\perp}\\ $$ > **Product-Angle Relation**: $$ \frac{\|\mathbf u\times\mathbf v\|}{\mathbf u\cdot\mathbf v}=\frac{\|\mathbf u\|\|\mathbf v\|\sin(\theta)}{\|\mathbf u\|\|\mathbf v\|\cos(\theta)}=\tan(\theta)\\ \frac{\|\mathbf u\times\mathbf v\|}{\|\mathbf u\|\|\mathbf v\|}=\frac{\mathbf u^{\perp}\cdot\mathbf v}{\|\mathbf u\|\|\mathbf v\|}=\sin(\theta)\\ \frac{\mathbf u\cdot\mathbf v}{\|\mathbf u\|\|\mathbf v\|}=\cos(\theta) $$ > **Cosine Law**: $$ \begin{cases} \|\mathbf u\pm\mathbf v\|^2=\|\mathbf u\|^2\pm2\|\mathbf u\|\|\mathbf v\|\cos(\theta)+\|\mathbf v\|^2\\ \theta=\angle(\mathbf u, \mathbf v)\\ \end{cases} $$ > **Pythagore Identity**: $$ \mathbf u\cdot\mathbf v=0\Rightarrow\|\mathbf u\pm\mathbf v\|^2=\|\mathbf u\|^2+\|\mathbf v\|^2\\ \|\mathbf u\|^2=(\mathbf u\cdot\widehat{\mathbf v})^2+\|\mathbf u-(\mathbf u\cdot\widehat{\mathbf v})\widehat{\mathbf v}\|^2 $$ > **B.C.S Inequality (Bunhiacopxki-Cauchy-Schwarz)**: $$ \|\mathbf u\cdot\mathbf v\|\leq\|\mathbf u\|\|\mathbf v\| $$ > **Triangle Inequality**: $$ \|\mathbf u+\mathbf v\|\leq\|\mathbf u\|+\|\mathbf v\| $$ > **Reversed Triangle Inequality**: $$ \|\mathbf u-\mathbf v\|\geq\|\mathbf u\|-\|\mathbf v\| $$ > **Extended Triangle Inequality**: $$ \|\mathbf u-\mathbf w\|\leq\|\mathbf u-\mathbf v\|+\|\mathbf v-\mathbf w\| $$ --- --- --- --- --- ## <center> C. Hàm tiện ích </center> --- ### <center> C.1) Hàm tiện ích chuyển đổi hệ </center> > **Casterian ↦ Polar**: `toPolar(u) =` $$ \text{pair}(r;\ \theta) = \text{pair}\left(\sqrt{u_x^2+u_y^2};\ \text{atan2}(y,x)\right)=\text{pair}\left(\text{mag}_{\mathbf u};\ \text{polar}_{\mathbf u}\right) $$ `Note:` pair(r, θ) không nhất thiết phải cùng kiểu dữ liệu > > **Polar ↦ Casterian:** `toCasterian(r, θ) =` $$ \text{vector2D}(u_x, u_y) = \text{vector2D}(r\cos(\theta);\ r\sin(\theta)) $$ --- ### <center> C.2) Hàm tiện ích radian </center> > **Radian ↦ Radian[0, 2π)**: `radNorm(radian θ) =` $$ ((\theta\ \%\ 2\pi)+2\pi)\ \%\ 2\pi $$ > **Radian ↦ Degree**: `radToDeg(radian θ) =` ==`deg(radian θ) =`== $$ \frac{\theta}{2\pi} \times 360^\circ $$ > **Radian ↦ Hour**: `radToHour(radian θ) =` $$ \frac{\theta}{2\pi} \times 24h $$ > **Radian ↦ Minute**: `radToMinute(radian θ) =` $$ \frac{\theta}{2\pi} \times 1440m $$ > **Radian ↦ Second**: `radToSecond(radian θ) =` $$ \frac{\theta}{2\pi} \times 86400s $$ > **Radian ↦ Clock[0h,24h)**: `radToClock(radian θ) =` $$ \text{vector}(hour, minute, second, nsf)\\ \text{for} \begin{cases} hour = \left\lfloor\text{toHour}(\text{toNormRad}(\theta))\right\rfloor\ \%\ 24\\ minute = \left\lfloor\text{toMinute}(\text{toNormRad}(\theta))\right\rfloor\ \%\ 60\\ second = \left\lfloor\text{toSecond}(\text{toNormRad}(\theta))\right\rfloor\ \%\ 60\\ nsf = \left\lfloor(\text{toSecond}(\text{toNormRad}(\theta)) - second) \div 10^9\right\rfloor \end{cases} $$ `Note:` nsf = nanosecond fraction (but converted to integer) > **Clock[0h,24h) ↦ Radian[0, 2π)**: `clockToRad(hour, minute, second, nsf) = ` $$ 2\pi\times\left(\frac{hour}{24} + \frac{minute}{1440} + \frac{second}{86400} + \frac{nsf}{86400\cdot10^9}\right) $$ `Default:` $hour:=0, minute:=0, second:=0, nsf:=0$ --- ### <center> C.3) Hàm tiện ích degree </center> > **Degree ↦ Degree[0°, 360°)**: `degNorm(degree ϕ) =` $$ ((\theta\ \%\ 360°)+360°)\ \%\ 360° $$ > **Degree ↦ Radian**: `degToRad(degree ϕ) =` ==`rad(degree ϕ) =`== $$ \frac{\phi}{360^\circ}\times 2\pi $$ > **Degree ↦ Hour**: `degToHour(degree ϕ) =` $$ \frac{\phi}{360^\circ}\times 24h $$ > **Degree ↦ Minute**: `degToMinute(degree ϕ) =` $$ \frac{\phi}{360^\circ}\times 1440m $$ > **Degree ↦ Second**: `degToSecond(degree ϕ) =` $$ \frac{\phi}{360^\circ}\times 86400s $$ > **Degree ↦ Clock[0h,24h)**: `degToClock(radian ϕ) =` $$ \text{vector}(hour, minute, second, nanosecond)\\ \text{for}\begin{cases} hour = \left\lfloor\text{toHour}(\text{toNormDeg}(\phi))\right\rfloor\ \%\ 24\\ minute = \left\lfloor\text{toMinute}(\text{toNormDeg}(\phi))\right\rfloor\ \%\ 60\\ second = \left\lfloor\text{toSecond}(\text{toNormDeg}(\phi))\right\rfloor\ \%\ 60\\ nanosecond = \text{toSecond}(\text{toNormDeg}(\phi)) - second \end{cases} $$ > **Clock[0h,24h) ↦ Degree[0°, 360°)**: `clockToRad(hour, minute, second, nsf) = ` $$ 360^\circ\times\left(\frac{hour}{24} + \frac{minute}{1440} + \frac{second}{86400} + \frac{nsf}{86400\cdot10^9}\right) $$ `Default:` $hour:=0, minute:=0, second:=0, nsf:=0$ --- ### <center> C.4) Hàm tiện ích số phức </center> > **Vector ↦ Complex**: `toComplex(u) = cplx(u) =` $$ \text{complex}(u_x;\ u_y) $$ > **Vector * Vector ↦ Complex**: `complexMultiplication(u, v) = mul(u, v) =` $$\mathbf u\mathbf v=\text{complex}(u_xv_x-u_yv_y;u_xv_y+u_yv_x) $$ > **Vector / Vector ↦ Complex**: `complexDivision(u, v) = div(u, v) =` $$\mathbf u\div\mathbf v =\text{complex}\left(\frac{\mathbf u\cdot\mathbf v}{\|\mathbf v\|};\ \frac{\mathbf v\times\mathbf u}{\|\mathbf v\|}\right) =\text{complex}\left(\frac{u_xv_x + u_yv_y}{u_y^2+v_y^2};\ \frac{u_yv_x-u_xv_y}{u_y^2+v_y^2}\right) $$ --- ### <center> C.5) Hàm tiện ích chỉ hướng </center> > **Quadrant Function**: ==`quadrantValue(u) =`== $$ \begin{cases} -4&,u_x=0\land u_y>0&&\text{phần âm trục tung }Oy^-\\ -3&,u_x<0\land u_y=0&&\text{phần âm trục hoành }Ox^-\\ -2&,u_x=0\land u_y>0&&\text{phần dương trục tung }Oy^+\\ -1&,u_x>0\land u_y=0&&\text{phần dương trục hoành }Ox^+\\ \ \ \ 0&,u_x=0\land u_y=0&&\text{gốc toạ độ } O(0;0)\\ +1&,u_x>0\land u_y>0&&\text{góc phần tư thứ }I\\ +2&,u_x<0\land u_y>0&&\text{góc phần tư thứ }II\\ +3&,u_x<0\land u_y<0&&\text{góc phần tư thứ }III\\ +4&,u_x>0\land u_y<0&&\text{góc phần tư thứ }IV\\ \end{cases}\\ $$ `quadrantString(u) =` $$ \begin{cases} \texttt{"Negative Vertical Axis"}&,u_x=0\land u_y>0&&\\ \texttt{"Negative Horizontal Axis"}&,u_x<0\land u_y=0&&\\ \texttt{"Positive Vertical Axis"}&,u_x=0\land u_y>0&&\\ \texttt{"Positive Horizontal Axis"}&,u_x>0\land u_y=0&&\\ \texttt{"Origin Position"}&,u_x=0\land u_y=0&&\\ \texttt{"First Quadrant"}&,u_x>0\land u_y>0&&\\ \texttt{"Second Quadrant"}&,u_x<0\land u_y>0&&\\ \texttt{"Third Quadrant"}&,u_x<0\land u_y<0&&\\ \texttt{"Fourth Quadrant"}&,u_x>0\land u_y<0&&\\ \end{cases}\\ $$ > **Angularity Function**: ==`angularityValue(u, v, [θ]) =`== $$ \begin{cases} -3 &,x=y=0&&\mathbf u\text{ có góc bất định với }\mathbf v\\ -2 &,x>y=0&&\mathbf u\text{ tạo thành góc không với }\mathbf v\\ -1 &,xy>0&&\mathbf u\text{ tạo thành góc nhọn với }\\ \ \ \ 0 &,y\neq x=0&&\mathbf u\text{ tạo thành góc vuông với }\mathbf v\\ +1 &,xy<0&&\mathbf u\text{ tạo thành góc tù với }\\ +2 &,x<y=0&&\mathbf u\text{ tạo thàng góc thẳng với }\mathbf v\\ +3 &,xy=\text{NaN}&&\mathbf u\text{ không có góc xác định với }\mathbf v\\ \end{cases}\\ \text{với}\begin{cases} x = (u_x + v_x)\cos(\theta) - (u_y + v_y)\sin(\theta)\\ y = (u_x + v_x)\sin(\theta) + (u_y + v_y)\cos(\theta)\\ \end{cases}\\ $$ `angularityString(u, v, [θ]) =` $$ \begin{cases} \texttt{"Ambiguous Angle"}&,x=y=0&&\mathbf u\text{ có góc bất định với }\mathbf v\\ \texttt{"Zero Angle"}&,x>y=0&&\mathbf u\text{ tạo thành góc không với }\mathbf v\\ \texttt{"Acute Angle"}&,xy>0&&\mathbf u\text{ tạo thành góc nhọn với }\\ \texttt{"Right Angle"}&,y\neq x=0&&\mathbf u\text{ tạo thành góc vuông với }\mathbf v\\ \texttt{"Obtuse Angle"}&,xy<0&&\mathbf u\text{ tạo thành góc tù với }\\ \texttt{"Complete Angle"}&,x<y=0&&\mathbf u\text{ tạo thàng góc thẳng với }\mathbf v\\ \texttt{"Invalid Angle"}&,xy=\text{NaN}&&\mathbf u\text{ không có góc xác định với }\mathbf v\\ \end{cases}\\ \text{với}\begin{cases} x = (u_x + v_x)\cos(\theta) - (u_y + v_y)\sin(\theta)\\ y = (u_x + v_x)\sin(\theta) + (u_y + v_y)\cos(\theta)\\ \end{cases}\\ $$ `Default:` $\theta := \frac{\pi}{2} = 90^{\circ}$ > **Relative Direction**: ==`relativeValue(u, v, [θ]) =`== $$ \begin{cases} -4&,x=0\land y>0&&\mathbf u\text{ vuông góc bên phải với }\mathbf v\\ -3&,x<0\land y=0&&\mathbf u\text{ ngược hướng song song với }\mathbf v\\ -2&,x=0\land y>0&&\mathbf u\text{ vuông góc bên trái với }\mathbf v\\ -1&,x>0\land y=0&&\mathbf u\text{ cùng hướng song song với }\mathbf v\\ \ \ \ 0&,x=0\land y=0&&\mathbf u\text{ trùng với }\mathbf v\\ +1&,x>0\land y>0&&\mathbf u\text{ tạo thành góc nhọn, hướng sang bên trái}\\ +2&,x<0\land y>0&&\mathbf u\text{ tạo thành góc tù, hướng sang bên trái}\\ +3&,x<0\land y<0&&\mathbf u\text{ tạo thành góc tù, hướng sang bên phải}\\ +4&,x>0\land y<0&&\mathbf u\text{ tạo thành góc nhọn, hướng sang bên phải}\\ \end{cases}\\ \text{với}\begin{cases} x = (u_x + v_x)\cos(\theta) - (u_y + v_y)\sin(\theta)\\ y = (u_x + v_x)\sin(\theta) + (u_y + v_y)\cos(\theta)\\ \end{cases}\\ $$ `relativeString(u, v, [θ]) =` $$ \begin{cases} \texttt{"Right-hand Perpendicular"}&,x=0\land y>0\\ \texttt{"Parallel"}&,x<0\land y=0\\ \texttt{"Left-hand Perpendicular"}&,x=0\land y>0\\ \texttt{"Antiparallel"}&,x>0\land y=0\\ \texttt{"Equivalent"}&,x=0\land y=0\\ \texttt{"Left-hand Acute"}&,x>0\land y>0\\ \texttt{"Left-hand Obtuse"}&,x<0\land y>0\\ \texttt{"Right-hand Obtuse"}&,x<0\land y<0\\ \texttt{"Right-hand Acute"}&,x>0\land y<0\\ \end{cases}\\ \text{với}\begin{cases} x = (u_x + v_x)\cos(\theta) - (u_y + v_y)\sin(\theta)\\ y = (u_x + v_x)\sin(\theta) + (u_y + v_y)\cos(\theta)\\ \end{cases}\\ $$ `Default:` $\theta := 0$ > **Cardinal Direction**: ==`cardinalValue(u) =`== $$ \begin{cases} -1 &, (u_x = u_y = 0)\\ 0 &, ({1\pi/4} \leq \theta < {3\pi/4}) \\ 1 &, ({3\pi/4} \leq \theta < {5\pi/4}) \\ 2 &, ({5\pi/4} \leq \theta < {7\pi/4}) \\ 3 &, ({7\pi/4} \leq \theta < {8\pi/4}) \lor ({0\pi/4} \le \theta < {1\pi/4}) \\ \end{cases} $$ `cardinalString(u) =` $$ \begin{cases} \texttt{"Center"} &, (u_x = u_y = 0)\\ \texttt{"East"} &, ({7\pi/4} \leq \theta < {8\pi/4}) \lor ({0\pi/4} \le \theta < {1\pi/4}) \\ \texttt{"North"} &, ({1\pi/4} \leq \theta < {3\pi/4}) \\ \texttt{"West"} &, ({3\pi/4} \leq \theta < {5\pi/4}) \\ \texttt{"South"} &, ({5\pi/4} \leq \theta < {7\pi/4}) \\ \end{cases} $$ > **Intercardinal/Ordinal Direction**: ==`ordinalValue(u) =`== $$ \begin{cases} -1 &, (u_x = u_y = 0)\\ 0 &, ({15\pi/8} \leq \theta < {16\pi/8}) \lor ({0\pi/8} \le \theta < {1\pi/8}) \\ 1 &, ({1\pi/8} \leq \theta < {3\pi/8}) \\ 2 &, ({3\pi/8} \leq \theta < {5\pi/8}) \\ 3 &, ({5\pi/8} \leq \theta < {7\pi/8}) \\ 4 &, ({7\pi/8} \leq \theta < {9\pi/8}) \\ 5 &, ({9\pi/8} \leq \theta < {11\pi/8}) \\ 6 &, ({11\pi/8} \leq \theta < {13\pi/8}) \\ 7 &, ({13\pi/8} \leq \theta < {15\pi/8}) \\ \end{cases} $$ `ordinalString(u) =` $$ \begin{cases} \texttt{"Center"} &, (u_x = u_y = 0)\\ \texttt{"East"} &, ({15\pi/8} \leq \theta < {16\pi/8}) \lor ({0\pi/8} \le \theta < {1\pi/8}) \\ \texttt{"Northeast"} &, ({1\pi/8} \leq \theta < {3\pi/8}) \\ \texttt{"North"} &, ({3\pi/8} \leq \theta < {5\pi/8}) \\ \texttt{"Northwest"} &, ({5\pi/8} \leq \theta < {7\pi/8}) \\ \texttt{"West"} &, ({7\pi/8} \leq \theta < {9\pi/8}) \\ \texttt{"Southwest"} &, ({9\pi/8} \leq \theta < {11\pi/8}) \\ \texttt{"South"} &, ({11\pi/8} \leq \theta < {13\pi/8}) \\ \texttt{"Southeast"} &, ({13\pi/8} \leq \theta < {15\pi/8}) \\ \end{cases} $$ > **Halfwin Direction**: ==`halfwindValue(u) =`== $$ \begin{cases} -1 &, (u_x = u_y = 0)\\ 0 &, ({31\pi/16} \leq \theta < {32\pi/16}) \lor ({0\pi/16} \le \theta < {1\pi/16}) \\ 1 &, ({1\pi/16} \leq \theta < {3\pi/16}) \\ 2 &, ({3\pi/16} \leq \theta < {5\pi/16}) \\ 3 &, ({5\pi/16} \leq \theta < {7\pi/16}) \\ 4 &, ({7\pi/16} \leq \theta < {9\pi/16}) \\ 5 &, ({9\pi/16} \leq \theta < {11\pi/16}) \\ 6 &, ({11\pi/16} \leq \theta < {13\pi/16}) \\ 7 &, ({13\pi/16} \leq \theta < {15\pi/16}) \\ 8 &, ({15\pi/16} \leq \theta < {17\pi/16}) \\ 9 &, ({17\pi/16} \leq \theta < {19\pi/16}) \\ 10 &, ({19\pi/16} \leq \theta < {21\pi/16}) \\ 11 &, ({21\pi/16} \leq \theta < {23\pi/16}) \\ 12 &, ({23\pi/16} \leq \theta < {25\pi/16}) \\ 13 &, ({25\pi/16} \leq \theta < {27\pi/16}) \\ 14 &, ({27\pi/16} \leq \theta < {29\pi/16}) \\ 15 &, ({29\pi/16} \leq \theta < {31\pi/16}) \\ \end{cases} $$ `halfwindString(u) =` $$ \begin{cases} \texttt{"Center"} &, (u_x = u_y = 0)\\ \texttt{"East"} &, ({31\pi/16} \leq \theta < {32\pi/16}) \lor ({0\pi/16} \le \theta < {1\pi/16}) \\ \texttt{"Northeast by East"} &, ({1\pi/16} \leq \theta < {3\pi/16}) \\ \texttt{"Northeast"} &, ({3\pi/16} \leq \theta < {5\pi/16}) \\ \texttt{"North by Northeast"} &, ({5\pi/16} \leq \theta < {7\pi/16}) \\ \texttt{"North"} &, ({7\pi/16} \leq \theta < {9\pi/16}) \\ \texttt{"North by Northwest"} &, ({9\pi/16} \leq \theta < {11\pi/16}) \\ \texttt{"Northwest"} &, ({11\pi/16} \leq \theta < {13\pi/16}) \\ \texttt{"Northwest by West"} &, ({13\pi/16} \leq \theta < {15\pi/16}) \\ \texttt{"West"} &, ({15\pi/16} \leq \theta < {17\pi/16}) \\ \texttt{"West by Southwest"} &, ({17\pi/16} \leq \theta < {19\pi/16}) \\ \texttt{"Southwest"} &, ({19\pi/16} \leq \theta < {21\pi/16}) \\ \texttt{"South by Southwest"} &, ({21\pi/16} \leq \theta < {23\pi/16}) \\ \texttt{"South"} &, ({23\pi/16} \leq \theta < {25\pi/16}) \\ \texttt{"South by Southeast"} &, ({25\pi/16} \leq \theta < {27\pi/16}) \\ \texttt{"Southeast"} &, ({27\pi/16} \leq \theta < {29\pi/16}) \\ \texttt{"Southeast by East"} &, ({29\pi/16} \leq \theta < {31\pi/16}) \\ \end{cases} $$ > **Quarterwin Direction**: ==`quarterwindValue(u) =`== $$ \begin{cases} -1 &, (u_x = u_y = 0)\\ 0 &, ({63\pi/32} \leq \theta < {64\pi/32}) \lor ({0\pi/32} \le \theta < {1\pi/32}) \\ 1 &, ({1\pi/32} \leq \theta < {3\pi/32}) \\ 2 &, ({3\pi/32} \leq \theta < {5\pi/32}) \\ 3 &, ({5\pi/32} \leq \theta < {7\pi/32}) \\ 4 &, ({7\pi/32} \leq \theta < {9\pi/32}) \\ 5 &, ({9\pi/32} \leq \theta < {11\pi/32}) \\ 6 &, ({11\pi/32} \leq \theta < {13\pi/32}) \\ 7 &, ({13\pi/32} \leq \theta < {15\pi/32}) \\ 8 &, ({15\pi/32} \leq \theta < {17\pi/32}) \\ 9 &, ({17\pi/32} \leq \theta < {19\pi/32}) \\ 10 &, ({19\pi/32} \leq \theta < {21\pi/32}) \\ 11 &, ({21\pi/32} \leq \theta < {23\pi/32}) \\ 12 &, ({23\pi/32} \leq \theta < {25\pi/32}) \\ 13 &, ({25\pi/32} \leq \theta < {27\pi/32}) \\ 14 &, ({27\pi/32} \leq \theta < {29\pi/32}) \\ 15 &, ({29\pi/32} \leq \theta < {31\pi/32}) \\ 16 &, ({31\pi/32} \leq \theta < {33\pi/32}) \\ 17 &, ({33\pi/32} \leq \theta < {35\pi/32}) \\ 18 &, ({35\pi/32} \leq \theta < {37\pi/32}) \\ 19 &, ({37\pi/32} \leq \theta < {39\pi/32}) \\ 20 &, ({39\pi/32} \leq \theta < {41\pi/32}) \\ 21 &, ({41\pi/32} \leq \theta < {43\pi/32}) \\ 22 &, ({43\pi/32} \leq \theta < {45\pi/32}) \\ 23 &, ({45\pi/32} \leq \theta < {47\pi/32}) \\ 24 &, ({47\pi/32} \leq \theta < {49\pi/32}) \\ 25 &, ({49\pi/32} \leq \theta < {51\pi/32}) \\ 26 &, ({51\pi/32} \leq \theta < {53\pi/32}) \\ 27 &, ({53\pi/32} \leq \theta < {55\pi/32}) \\ 28 &, ({55\pi/32} \leq \theta < {57\pi/32}) \\ 29 &, ({57\pi/32} \leq \theta < {59\pi/32}) \\ 30 &, ({59\pi/32} \leq \theta < {61\pi/32}) \\ 31 &, ({61\pi/32} \leq \theta < {63\pi/32}) \\ \end{cases} $$ `quarterwindString(u) =` $$ \begin{cases} \texttt{"Center"} &, (u_x = u_y = 0)\\ \texttt{"East"} &, ({63\pi/32} \leq \theta < {64\pi/32}) \lor ({0\pi/32} \le \theta < {1\pi/32}) \\ \texttt{"East by North"} &, ({1\pi/32} \leq \theta < {3\pi/32}) \\ \texttt{"East-Northeast"} &, ({3\pi/32} \leq \theta < {5\pi/32}) \\ \texttt{"Northeast by East"} &, ({5\pi/32} \leq \theta < {7\pi/32}) \\ \texttt{"Northeast"} &, ({7\pi/32} \leq \theta < {9\pi/32}) \\ \texttt{"Northeast by North"} &, ({9\pi/32} \leq \theta < {11\pi/32}) \\ \texttt{"North-Northeast"} &, ({11\pi/32} \leq \theta < {13\pi/32}) \\ \texttt{"North by East"} &, ({13\pi/32} \leq \theta < {15\pi/32}) \\ \texttt{"North"} &, ({15\pi/32} \leq \theta < {17\pi/32}) \\ \texttt{"North by West"} &, ({17\pi/32} \leq \theta < {19\pi/32}) \\ \texttt{"North-Northwest"} &, ({19\pi/32} \leq \theta < {21\pi/32}) \\ \texttt{"Northwest by North"} &, ({21\pi/32} \leq \theta < {23\pi/32}) \\ \texttt{"Northwest"} &, ({23\pi/32} \leq \theta < {25\pi/32}) \\ \texttt{"Northwest by West"} &, ({25\pi/32} \leq \theta < {27\pi/32}) \\ \texttt{"West-Northwest"} &, ({27\pi/32} \leq \theta < {29\pi/32}) \\ \texttt{"West by North"} &, ({29\pi/32} \leq \theta < {31\pi/32}) \\ \texttt{"West"} &, ({31\pi/32} \leq \theta < {33\pi/32}) \\ \texttt{"West by South"} &, ({33\pi/32} \leq \theta < {35\pi/32}) \\ \texttt{"West-Southwest"} &, ({35\pi/32} \leq \theta < {37\pi/32}) \\ \texttt{"Southwest by West"} &, ({37\pi/32} \leq \theta < {39\pi/32}) \\ \texttt{"Southwest"} &, ({39\pi/32} \leq \theta < {41\pi/32}) \\ \texttt{"Southwest by South"} &, ({41\pi/32} \leq \theta < {43\pi/32}) \\ \texttt{"South-Southwest"} &, ({43\pi/32} \leq \theta < {45\pi/32}) \\ \texttt{"South by West"} &, ({45\pi/32} \leq \theta < {47\pi/32}) \\ \texttt{"South"} &, ({47\pi/32} \leq \theta < {49\pi/32}) \\ \texttt{"South by East"} &, ({49\pi/32} \leq \theta < {51\pi/32}) \\ \texttt{"South-Southeast"} &, ({51\pi/32} \leq \theta < {53\pi/32}) \\ \texttt{"Southeast by South"} &, ({53\pi/32} \leq \theta < {55\pi/32}) \\ \texttt{"Southeast"} &, ({55\pi/32} \leq \theta < {57\pi/32}) \\ \texttt{"Southeast by East"} &, ({57\pi/32} \leq \theta < {59\pi/32}) \\ \texttt{"East-Southeast"} &, ({59\pi/32} \leq \theta < {61\pi/32}) \\ \texttt{"East by South"} &, ({61\pi/32} \leq \theta < {63\pi/32}) \\ \end{cases} $$ --- ### <center> C.6) Biểu tượng </center> `quadrantSymbol(u) =` $$ \begin{cases} \texttt{'⍖'}&,u_x=0\land u_y>0&&\text{phần âm trục tung }Oy^-\\ \texttt{'⍅'}&,u_x<0\land u_y=0&&\text{phần âm trục hoành }Ox^-\\ \texttt{'⍏'}&,u_x=0\land u_y>0&&\text{phần dương trục tung }Oy^+\\ \texttt{'⍆'}&,u_x>0\land u_y=0&&\text{phần dương trục hoành }Ox^+\\ \texttt{'⨁'}&,u_x=0\land u_y=0&&\text{gốc toạ độ } O(0;0)\\ \texttt{'Ⅰ'}&,u_x>0\land u_y>0&&\text{góc phần tư thứ }I\\ \texttt{'Ⅱ'}&,u_x<0\land u_y>0&&\text{góc phần tư thứ }II\\ \texttt{'Ⅲ'}&,u_x<0\land u_y<0&&\text{góc phần tư thứ }III\\ \texttt{'Ⅳ'}&,u_x>0\land u_y<0&&\text{góc phần tư thứ }IV\\ \end{cases}\\ $$ `angularitySymbol(u, v, [θ]) =` $$ \begin{cases} \texttt{'𐽗'}&,x=y=0&&\mathbf u\text{ có góc bất định với }\mathbf v\\ \texttt{'⥉'}&,x>y=0&&\mathbf u\text{ tạo thành góc không với }\mathbf v\\ \texttt{'⦟'}&,xy>0&&\mathbf u\text{ tạo thành góc nhọn với }\\ \texttt{'⦜'}&,y\neq x=0&&\mathbf u\text{ tạo thành góc vuông với }\mathbf v\\ \texttt{'⦦'}&,xy<0&&\mathbf u\text{ tạo thành góc tù với }\\ \texttt{'⥈'}&,x<y=0&&\mathbf u\text{ tạo thàng góc thẳng với }\mathbf v\\ \texttt{'∅'}&,xy=\text{NaN}&&\mathbf u\text{ không có góc xác định với }\mathbf v\\ \end{cases}\\ \text{với}\begin{cases} x = (u_x + v_x)\cos(\theta) - (u_y + v_y)\sin(\theta)\\ y = (u_x + v_x)\sin(\theta) + (u_y + v_y)\cos(\theta)\\ \end{cases}\\ $$ `relativeSymbol(u, v, [θ]) =` $$ \begin{cases} \texttt{'⍆'}&,x=0\land y>0&&\mathbf u\text{ vuông góc bên phải với }\mathbf v\\ \texttt{'⇅'}&,x<0\land y=0&&\mathbf u\text{ ngược hướng song song với }\mathbf v\\ \texttt{'⍅'}&,x=0\land y>0&&\mathbf u\text{ vuông góc bên trái với }\mathbf v\\ \texttt{'⇈'}&,x>0\land y=0&&\mathbf u\text{ cùng hướng song song với }\mathbf v\\ \texttt{'≡'}&,x=0\land y=0&&\mathbf u\text{ trùng với }\mathbf v\\ \texttt{'⦭'}&,x>0\land y>0&&\mathbf u\text{ tạo thành góc nhọn, hướng sang bên trái}\\ \texttt{'⦯'}&,x<0\land y>0&&\mathbf u\text{ tạo thành góc tù, hướng sang bên trái}\\ \texttt{'⦮'}&,x<0\land y<0&&\mathbf u\text{ tạo thành góc tù, hướng sang bên phải}\\ \texttt{'⦬'}&,x>0\land y<0&&\mathbf u\text{ tạo thành góc nhọn, hướng sang bên phải}\\ \end{cases}\\ \text{với}\begin{cases} x = (u_x + v_x)\cos(\theta) - (u_y + v_y)\sin(\theta)\\ y = (u_x + v_x)\sin(\theta) + (u_y + v_y)\cos(\theta)\\ \end{cases}\\ $$ `cardinalSymbol(u) =` $$ \begin{cases} \texttt{'◆'} &, (u_x = u_y = 0)\\ \texttt{'⮙'} &, ({1\pi/4} \leq \theta < {3\pi/4}) \\ \texttt{'⮘'} &, ({3\pi/4} \leq \theta < {5\pi/4}) \\ \texttt{'⮛'} &, ({5\pi/4} \leq \theta < {7\pi/4}) \\ \texttt{'⮚'} &, ({7\pi/4} \leq \theta < {8\pi/4}) \lor ({0\pi/4} \le \theta < {1\pi/4}) \\ \end{cases} $$ `ordinalSymbol(u) =` $$ \begin{cases} \texttt{'◆'} &, u_x = u_y = 0\\ \texttt{'⮚'} &, ({15\pi/8} \leq \theta < {16\pi/8}) \lor ({0\pi/8} \le \theta < {1\pi/8}) \\ \texttt{'⬈'} &, ({1\pi/8} \leq \theta < {3\pi/8}) \\ \texttt{'⮙'} &, ({3\pi/8} \leq \theta < {5\pi/8}) \\ \texttt{'⬉'} &, ({5\pi/8} \leq \theta < {7\pi/8}) \\ \texttt{'⮘'} &, ({7\pi/8} \leq \theta < {9\pi/8}) \\ \texttt{'⬋'} &, ({9\pi/8} \leq \theta < {11\pi/8}) \\ \texttt{'⮛'} &, ({11\pi/8} \leq \theta < {13\pi/8}) \\ \texttt{'⬊'} &, ({13\pi/8} \leq \theta < {15\pi/8}) \\ \end{cases} $$ `halfwindSymbol(u) =` $$ \begin{cases} \texttt{'◆'} &, (u_x = u_y = 0)\\ \texttt{'⮚'} &, ({31\pi/16} \leq \theta < {32\pi/16}) \lor ({0\pi/16} \le \theta < {1\pi/16}) \\ \texttt{'⮫'} &, ({1\pi/16} \leq \theta < {3\pi/16}) \\ \texttt{'⬈'} &, ({3\pi/16} \leq \theta < {5\pi/16}) \\ \texttt{'⮭'} &, ({5\pi/16} \leq \theta < {7\pi/16}) \\ \texttt{'⮙'} &, ({7\pi/16} \leq \theta < {9\pi/16}) \\ \texttt{'⮬'} &, ({9\pi/16} \leq \theta < {11\pi/16}) \\ \texttt{'⬉'} &, ({11\pi/16} \leq \theta < {13\pi/16}) \\ \texttt{'⮪'} &, ({13\pi/16} \leq \theta < {15\pi/16}) \\ \texttt{'⮘'} &, ({15\pi/16} \leq \theta < {17\pi/16}) \\ \texttt{'⮨'} &, ({17\pi/16} \leq \theta < {19\pi/16}) \\ \texttt{'⬋'} &, ({19\pi/16} \leq \theta < {21\pi/16}) \\ \texttt{'⮮'} &, ({21\pi/16} \leq \theta < {23\pi/16}) \\ \texttt{'⮛'} &, ({23\pi/16} \leq \theta < {25\pi/16}) \\ \texttt{'⮯'} &, ({25\pi/16} \leq \theta < {27\pi/16}) \\ \texttt{'⬊'} &, ({27\pi/16} \leq \theta < {29\pi/16}) \\ \texttt{'⮩'} &, ({29\pi/16} \leq \theta < {31\pi/16}) \\ \end{cases} $$ `quarterwindSymbol(u) =` $$ \begin{cases} \texttt{"◆"} &, (u_x = u_y = 0)\\ \texttt{"⮚"} &, ({63\pi/32} \leq \theta < {64\pi/32}) \lor ({0\pi/32} \le \theta < {1\pi/32}) \\ \texttt{"⮫-"} &, ({1\pi/32} \leq \theta < {3\pi/32}) \\ \texttt{"⮫"} &, ({3\pi/32} \leq \theta < {5\pi/32}) \\ \texttt{"⮫+"} &, ({5\pi/32} \leq \theta < {7\pi/32}) \\ \texttt{"⬈"} &, ({7\pi/32} \leq \theta < {9\pi/32}) \\ \texttt{"⮭-"} &, ({9\pi/32} \leq \theta < {11\pi/32}) \\ \texttt{"⮭"} &, ({11\pi/32} \leq \theta < {13\pi/32}) \\ \texttt{"⮭+"} &, ({13\pi/32} \leq \theta < {15\pi/32}) \\ \texttt{"⮙"} &, ({15\pi/32} \leq \theta < {17\pi/32}) \\ \texttt{"⮬-"} &, ({17\pi/32} \leq \theta < {19\pi/32}) \\ \texttt{"⮬"} &, ({19\pi/32} \leq \theta < {21\pi/32}) \\ \texttt{"⮬+"} &, ({21\pi/32} \leq \theta < {23\pi/32}) \\ \texttt{"⬉"} &, ({23\pi/32} \leq \theta < {25\pi/32}) \\ \texttt{"⮪-"} &, ({25\pi/32} \leq \theta < {27\pi/32}) \\ \texttt{"⮪"} &, ({27\pi/32} \leq \theta < {29\pi/32}) \\ \texttt{"⮪+"} &, ({29\pi/32} \leq \theta < {31\pi/32}) \\ \texttt{"⮘"} &, ({31\pi/32} \leq \theta < {33\pi/32}) \\ \texttt{"⮨-"} &, ({33\pi/32} \leq \theta < {35\pi/32}) \\ \texttt{"⮨"} &, ({35\pi/32} \leq \theta < {37\pi/32}) \\ \texttt{"⮨+"} &, ({37\pi/32} \leq \theta < {39\pi/32}) \\ \texttt{"⬋"} &, ({39\pi/32} \leq \theta < {41\pi/32}) \\ \texttt{"⮮-"} &, ({41\pi/32} \leq \theta < {43\pi/32}) \\ \texttt{"⮮"} &, ({43\pi/32} \leq \theta < {45\pi/32}) \\ \texttt{"⮮+"} &, ({45\pi/32} \leq \theta < {47\pi/32}) \\ \texttt{"⮛"} &, ({47\pi/32} \leq \theta < {49\pi/32}) \\ \texttt{"⮯-"} &, ({49\pi/32} \leq \theta < {51\pi/32}) \\ \texttt{"⮯"} &, ({51\pi/32} \leq \theta < {53\pi/32}) \\ \texttt{"⮯+"} &, ({53\pi/32} \leq \theta < {55\pi/32}) \\ \texttt{"⬊"} &, ({55\pi/32} \leq \theta < {57\pi/32}) \\ \texttt{"⮩-"} &, ({57\pi/32} \leq \theta < {59\pi/32}) \\ \texttt{"⮩"} &, ({59\pi/32} \leq \theta < {61\pi/32}) \\ \texttt{"⮩+"} &, ({61\pi/32} \leq \theta < {63\pi/32}) \\ \end{cases} $$ --- --- --- --- --- ## <center> D. Hàm tính toán </center> --- ### <center> D.1) Hàm tính giá trị thông dụng </center> > **Zero Check**: `u.isZero() = true` ==`⇔ is0(u) = true`== $$ \Leftrightarrow \mathbf u = \mathbf 0 \Leftrightarrow\begin{cases} u_x = 0\\ u_y = 0 \end{cases} $$ > > **Horizontal Position**: `u.horizontal() =` ==`u.x() =`== $$ u_x $$ > > **Vertical Position**: `u.vertical() =` ==`u.y() =`== $$ u_y $$ > > **Norm:** `u.norm(p) =` ==`norm(u, p) =`== $$ \|\mathbf u\|_p = (|u_x|^p+|u_y|^p)^{(1/p)} $$ `Default:` $p := 2$ > > **Length/Abs**: `u.length() = u.abs() =` ==`len(u) = abs(u) =`== $$ \|\mathbf u\|=\sqrt{u_x^2+u_y^2} $$ > **Squared Length**: `u.squaredLength() =` ==`sq(u)`== $$ u_x^2+u_y^2 $$ `Note:` Thường dùng với số nguyên $\in \mathbb{Z}$ cho bớt sai số > **Magnitude Position**: `u.r() = u.magnitude()` ==`r(u) = mag(u) =`== $$ \text{mag}_{\mathbf u}=\|\mathbf u\| $$ > **Polar Angle**: `u.theta() = u.polarAngle() = polarAngle(u) =` ==`theta(u) = polar(u) =`== $$ \text{atan2}(u_y; u_x) $$ > > **Angle Between Vectors**: `u.angle(v) =` ==`angle(u, v) =`== $$ \theta = (\text{atan2}(\mathbf u\times\mathbf v,\ \mathbf u\cdot\mathbf v) + \pi)\ \%\ 2\pi $$ > **Interior Angle**: `u.interiorAngle(v) =` ==`interior(u, v) =`== $$ \theta_{int} = 2\pi - \theta_{ext} = \cos^{-1}\left(\frac{u\cdot v}{\| u \| \| v \|}\right) $$ > **Exterior Angle**: `u.exteriorAngle(v) =` ==`exterior(u, v) =`== $$ \theta_{ext} = 2\pi - \theta_{int} = \sin^{-1}\left(\frac{u\times v}{\| u \| \| v \|}\right) $$ > **Manhattan/Taxicab Distance**: `manhattanDistance(u, v) =` ==`u.taxicab(v) =`== $$ \| \mathbf u - \mathbf v\|_x = \| \mathbf v - \mathbf u \|_x = \|u_x - v_x\| + \|u_y - v_y\| $$ > **Straight/Euclidean Distance**: `euclideanDistance(u, v)` ==`u.dist(v) =`== $$ \| \mathbf u - \mathbf v\| = \| \mathbf v - \mathbf u\| = \sqrt{(u_x-v_x)^2 + (u_y-v_y)^2} $$ > **Squared Euclidean Distance**: `squaredDistance(u, v) =` ==`u.sqdist(v)`== $$ \| \mathbf u - \mathbf v\|^2 = \| \mathbf v - \mathbf u\|^2 = (u_x-v_x)^2 + (u_y-v_y)^2 $$ `Note:` Không dùng công thức $\text{dist}(u, v)^2$ để tránh sai số --- ### <center> D.2) Hàm tính giá trị ít dùng </center> > **Scalar Projection**: `u.scalarProj(θ) = u.scalarProj(v) =` $$ \|\mathbf u\|\cos\theta=\frac{\mathbf u\cdot\mathbf v}{\|\mathbf v\|}=\frac{u_xv_x+u_yv_y}{\sqrt{v_x^2+v_y^2}} $$ > **Scalar Rejection**: `u.scalarRej(θ) = u.scalarRej(v) =` $$ \|\mathbf u\|\sin\theta=\frac{\mathbf u\cdot\mathbf v^{\perp}}{\|\mathbf v\|}=\frac{u_yv_x-u_xv_y}{\sqrt{v_x^2+v_y^2}} $$ --- ### <center> D.3) Hàm tính vector </center> > **Vector Projection**: `u.vectorProjection(v) =` ==`proj(u, v) =`== $$ \text{proj}_{\mathbf{v}}(\mathbf{u}) = \frac{\mathbf{u} \cdot \mathbf{v}}{\| \mathbf v \|^2} \times \mathbf v = \widehat{\mathbf u}\mathbf u.\text{scalarProj}(\mathbf v) $$ > > **Vector Rejection**: `u.vectorRejection(v) =` ==`rej(u, v) =`== $$ \text{rej}_{\mathbf{v}}(\mathbf{u}) = \frac{\mathbf{u}^{\perp}\cdot \mathbf{v}}{\| \mathbf v \|^2} \times \mathbf v = \mathbf u-\text{proj}_\mathbf v(\mathbf u) $$ > > **Dot Product**: `u.dotProduct(v) =` ==`dot(u, v) =`== $$ \mathbf u\cdot\mathbf v=u_x\times v_x+u_y\times v_y $$ > **Perp Dot Product**: `u.perpProduct(v) =` ==`perp(u, v) =`== $$ \mathbf u^{\perp}\cdot\mathbf v=u_x\times v_y-u_y\times v_x $$ > **2D Cross Product**: `u.crossProduct(v) =` ==`cross(u, v) =`== $$ \mathbf u\times\mathbf v=u_x\times v_y-u_y\times v_x $$ > **Wedge Product**: `u.wedgeProduct(v)` ==`wedge(u, v) =`== $$ \mathbf u\wedge\mathbf v=u_x\times v_y-u_y\times v_x $$ **Geometric & Commutator Product**: `u.geoProduct(v)` ==`geomul(u, v) =`== $$ \text{vector2D}(\mathbf{uv};\ \mathbf{vu}) $$ **Vector Geometric Inverse**: `u.geoInverse()` ==`geoinv(u) =`== $$ \mathbf u^{-1} = \frac{\mathbf u}{\|\mathbf u\|^2} = \frac{\widehat{\mathbf u}}{\|\mathbf u\|} $$ **Vector Geometric Division**: `u.geoDivision(v)` ==`geodiv(u, v) =`== $$ \frac{\mathbf u}{\mathbf v} = \mathbf u\left(\mathbf v^{-1}\right) = \frac{\mathbf u\mathbf v}{\|\mathbf v\|^2} $$ **Vector Cross Division**: `crossDivision(u×v, v, θ) =` $$ \mathbf u = \frac{\|\mathbf u\times\mathbf v\|\cot(\theta)\mathbf v-\mathbf v\times(\mathbf u\times \mathbf v)}{\|\mathbf v\|^2} $$ --- ### <center> D.4) Hàm biến đổi vector </center> #### <center> D.4.a) Hàm biến đổi tuyến tính vector </center> > **Swap Transformation**: `u.swap(v)` > **Negation Transformation**: `u.negation() =` $$ -\mathbf{u} = \text{vector2D}(-u_x;\ -u_y) $$ > **Conjugation Transformation**: `u.conjugation() =` $$ \overline{\mathbf u} = \text{vector2D}(u_x;\ -u_y) $$ > > **Translation Transformation**: `u.translate(v) = u.translate(vx, vy) =` $$ \mathbf u \mapsto \mathbf u + \mathbf v = \text{vector2D}(u_x + v_x;\ u_y + v_y) $$ > **Reversion Transformation**: `u.reverse() =` $$ \text{rev}_{\mathbf u} = \text{vector2D}(u_y;\ u_x) $$ > **Reflection Transformation**: `u.reflection(v) =` $$ \overset{\leftrightarrow\hspace{-6.5pt}{\small|}}{\text{ Ref}}_{\mathbf{v}}(\mathbf{u}) = 2\text{proj}_\mathbf v(\mathbf u) - \mathbf u = 2\frac{\mathbf u\cdot\mathbf v}{\|\mathbf v\|^2}\mathbf v-\mathbf u $$ > **Mirror-X/Flip-Y Transformation**: `u.mirror_x() = u.flip_y() =` $$ \overset{\leftarrow\hspace{-5.5pt}{\small|}}{\text{ R}}(\mathbf u) = \text{vector2D}(u_x;\ -u_y) $$ > **Mirror-Y/Flip-X Transformation**: `u.mirror_y() = u.flip_x() =` $$ \overset{\downarrow\hspace{-6.5pt}{\overline{\ \ \ }}}{\text{ R}}(\mathbf u)=\text{vector2D}(-u_x;\ u_y) $$ > **Mirror-XY/Flip-XY/Negation Transformation**: `u.mirror_xy() = u.flip_xy() = u.negation() =` $$ \overset{\swarrow\hspace{-6.5pt}{\small\backslash}}{\text{ R}}(\mathbf u)=\text{vector2D}(-u_x;\ -u_y) $$ > **Scale Transformation**: `u.scale(α, [β]) =` $$ \overset{\nearrow\hspace{-9.5pt}\swarrow}{\text{Scale}}_\text{ }(\mathbf u, \alpha, \beta) = \text{vector2D}(\alpha u_x;\ \beta u_y) $$ `Default:` $\beta := \alpha$ `Note:` > > Khi $\left[\begin{array}{l}\alpha = 1, \beta > 1\\\alpha > 1, \beta = 1\end{array}\right.$ thì gọi là hàm `stretch` ($\nwarrow\hspace{-9pt}\nearrow$) > > Khi $\left[\begin{array}{l}\alpha < 1, \beta = 1\\\alpha = 1, \beta < 1\end{array}\right.$ thì gọi là hàm `squash` ($\swarrow\hspace{-9pt}\searrow$) > > Khi $\left[\begin{array}{l}\alpha < 1, \beta > 1\\\alpha > 1, \beta < 1\end{array}\right.$ thì gọi là hàm `squeeze` ($\uparrow\downarrow$) #### <center> D.4.c) Hàm biến đổi khác </center> > **Unitization Transformation**: `u.unit() = u.normalized() =` $$ \widehat{\mathbf u} = \text{vector2D}\left(\frac{u_x}{\|\mathbf u\|}, \frac{u_y}{\|\mathbf u\|}\right) $$ `Note:` Cẩn thận khi $\mathbf u=\mathbf 0$, và cẩn thận nhầm với hàm`norm(u, p)` > **Reciprocity Transformation**: `u.reciprocal() =` $$ \text{rec}_{\mathbf u} = \text{vector2D}\left(\frac{1}{u_x};\ \frac{1}{u_y}\right) $$ `Note:` Cẩn thận khi $u_x=0$ hoặc $u_y = 0$ > **Rotation Transformation**: `u.rotate(θ, [isClockwise]) =` $$ \begin{cases} \overset{\curvearrowleft}{R}_{\theta}(u)=\left(u_x\cos(\theta)-u_y\sin(\theta);\ u_y\cos(\theta)+u_x\sin(\theta)\right)&,isClockwise=false\\ \overset{\curvearrowright}{R}_{\theta}(u)=\left(u_x\cos(\theta)+u_y\sin(\theta);\ u_y\cos(\theta)-u_x\sin(\theta)\right)&,isClockwise=true\\ \end{cases} $$ `Default:` $\theta := \frac{\pi}{2}$ (quay $90^\circ$) và $isClockwise := true$ (quay cùng chiều kim đồng hồ) > > **Clamp Transformation**: `u.clamp(α, [β]) = ` $$ \text{vector2D}\left(\text{sign}(u_x)\min(|u.x|, |\alpha|) ;\ \text{sign}(u_y)\min(|u.y|, |\beta|)\right) $$ `Default:` $\beta := \alpha$ > **Shear Transformation**: `u.shear(α, [β]) =` $$ \overset{\Lsh\Rsh}{\text{T}}_\text{shear}(\mathbf u, \alpha,\beta)=\text{vector2D}\left(u_x+\alpha u_y;\ u_y+\beta u_x\right) $$ `Default:` $\beta := 0$ > **Linear Transformation**: `u.shear(α1, α2, β1, β2) =` $$ \text{T}(\mathbf u, \alpha_1, \alpha_2, \beta_1, \beta_2)=\text{vector2D}\left(\alpha_1u_x+\alpha_2u_y;\ \beta_1u_y+\beta_2u_x\right) $$ > **Component-wise Transformation**: `u.componentwise(f) =` $$ \mathbf u\odot f=\text{vector2D}\left(f(u_x);\ f(u_y)\right) $$ --- --- --- --- --- ## <center> E. Hàm kiểm tra </center> --- ### <center> E.1) Kiểm tra tính bằng nhau </center> > **Sign Function**: ==`sign(scalar x) =`== $$ [x > 0] - [x < 0] =\begin{cases} +1&,x>0\\ \ \ 0&,x=0\\ -1&,x<0\\ \end{cases} $$ `Note:` $0$ và $x$ nên cùng kiểu dữ liệu, và dấu $[x = y]$ là [iverson brackets](https://en.wikipedia.org/wiki/Iverson_bracket) `Note:` Có thể xem `quadrant()` là sign function cho vector > > **Float Equality**: `isEqual(scalar u, scalar v, high-precision ε) = true` $$ \Leftrightarrow \begin{cases} |u_x-v_x| \leq \varepsilon\\ |u_y-v_y| \leq \varepsilon\\ \end{cases} $$ `Default:` $\varepsilon = 10^{-9}$ > **Equality Function**: ==`equalityValue(scalar x, scalar y) =`== $$ \begin{cases} -9&, \vert x-y\vert\leq10^{-9}\\ -8&, 10^{-9} < \vert x-y\vert\leq10^{-8}\\ -7&, 10^{-8} < \vert x-y\vert\leq10^{-7}\\ -6&, 10^{-7} < \vert x-y\vert\leq10^{-6}\\ -5&, 10^{-6} < \vert x-y\vert\leq10^{-5}\\ -4&, 10^{-5} < \vert x-y\vert\leq10^{-4}\\ -3&, 10^{-4} < \vert x-y\vert\leq10^{-3}\\ -2&, 10^{-3} < \vert x-y\vert\leq10^{-2}\\ -1&, 10^{-2} < \vert x-y\vert\leq10^{-1}\\ \ \ \ 0&,x\not\approx y\\ \end{cases} $$ --- ### <center> E.2) Kiểm tra tính trực giao </center> > **Orthogonal Check**: `isOrthogonal(u, v) = true` $$ \Leftrightarrow \left[\begin{array}{l} \mathbf u\cdot\mathbf v=0\\ \mathbf u\times\mathbf v=0\\ \end{array}\right. $$ > **Dilation Factor**: `u.dilation(v) =` $$ \begin{cases} \frac{u_x}{v_x}&,(v_xv_y\neq 0) \land \left(\frac{u_x}{v_x} = \frac{u_y}{v_y}\in\mathbb{R}\right)\\ +\infty&,\left(\frac{u_x}{v_x}=\frac{u_y}{v_y}=+\infty\right)\\ -\infty&,\left(\frac{u_x}{v_x}=\frac{u_y}{v_y}=-\infty\right)\\ \text{NaN}&,\left(\frac{u_y}{v_y}=\text{NaN}\right)\lor\left(\frac{u_x}{v_x}=\text{NaN}\right)\lor\left(\frac{u_y}{v_y}=\text{NaN}\right)\lor\left(\frac{u_x}{v_x} \neq \frac{u_y}{v_y}\right)\\ \end{cases} $$ > **Collinear Check**: `isColinear(u, v) = true` $$ \Leftrightarrow \exists k=\text{dilation}(\mathbf u, \mathbf v)\to\mathbf u=k\mathbf v\\ \Leftrightarrow\mathbf u\times\mathbf v=0 $$ > **Parallel Check**: `isParallel(u, v) = true` $$ \Leftrightarrow \begin{cases} \mathbf u\times\mathbf v=0\\ \mathbf u\cdot\mathbf v>0 \end{cases} $$ > **Antiparallel Check**: `isAntiparallel(u, v) = true` $$ \Leftrightarrow \begin{cases} \mathbf u\times\mathbf v=0\\ \mathbf u\cdot\mathbf v<0 \end{cases} $$ > **Zero Angle Check**: `isZeroAngle(u, v) = true` $$ \Leftrightarrow \measuredangle(\mathbf{u}, \mathbf{v})=0^\circ \Leftrightarrow\theta=0 \Leftrightarrow\mathbf u\cdot\mathbf v=\|\mathbf u\|\cdot\|\mathbf v\| $$ > **Right Angle Check**: `isPerpendicular(u, v) = isRightAngle(u, v) = true` $$ \Leftrightarrow \measuredangle(\mathbf{u},\mathbf{v})=90^\circ \Leftrightarrow\theta=\frac{\pi}{2} \Leftrightarrow\mathbf u\perp\mathbf v \Leftrightarrow\mathbf u\cdot\mathbf v=0 $$ > **Straight Angle Check**: `isStraightAngle(u, v) = true` $$ \Leftrightarrow \measuredangle(\mathbf{u}, \mathbf{v})=180^\circ \Leftrightarrow\theta=\pi \Leftrightarrow\mathbf u\cdot\mathbf v=-\|\mathbf u\|\cdot\|\mathbf v\| $$ > --- ### <center> E.3) Kiểm tra góc xiên </center> > **Left-Right Side Indicator**: `sideX(u, [v]) =` $$ \begin{cases} +1&,\mathbf u\cdot\mathbf v>0&&\text{same side}\\ \ \ \ 0&,\mathbf u\cdot\mathbf v=0&&\text{perpendicular}\\ -1&,\mathbf u\cdot\mathbf v<0&&\text{opposite side}\\ \end{cases} $$ `Default:` $\mathbf v = \mathbf 0 \Leftrightarrow side(\mathbf u) = sign(u_y)$ `Note:` so với đường thẳng vuông góc với phương của $\mathbf u$ > **Top-Down Side Indicator**: `sideY(u, [v]) =` $$ \begin{cases} +1&,\mathbf u\times\mathbf v>0&&\text{same half}\\ \ \ \ 0&,\mathbf u\times\mathbf v=0&&\text{collinear}\\ -1&,\mathbf u\times\mathbf v<0&&\text{opposite half}\\ \end{cases} $$ `Default:` $\mathbf v = \mathbf 0$ `Note:` so với đường thẳng đi qua $\mathbf u$ > > **Acute Angle Check**: `isAcuteAngle(u, v) = true` $$ \Leftrightarrow \measuredangle(\mathbf{u},\mathbf{v})\in(0^\circ, 90^\circ) \Leftrightarrow 0 < \theta < \frac{\pi}{2} \Leftrightarrow\mathbf u\cdot\mathbf v>0 $$ > **Obtuse Angle Check**: `isObtuseAngle(u, v) = true` $$ \Leftrightarrow \measuredangle(\mathbf{u},\mathbf{v})\in(90^\circ,180^\circ) \Leftrightarrow \frac{\pi}{2} < \theta < \pi \Leftrightarrow\mathbf u\cdot\mathbf v<0 $$ > **Reflex Angle Check**: `isReflexAngle(u, v) = !isReflexAngle(v, u) = true` $$ \Leftrightarrow \measuredangle(\mathbf{u},\mathbf{v})\in(-180^\circ,0^\circ) \Leftrightarrow \pi < \theta < 2\pi \Leftrightarrow\mathbf u\times\mathbf v<0 $$ --- ### <center> E.4) Hàm kiểm tra hướng góc </center> > **Orientability Function**: `orient(u, v) =` $$ \begin{cases} +1&,\mathbf u\times\mathbf v>0&&\text{counter-clockwise}\\ \ \ \ 0&,\mathbf u\times\mathbf v=0&&\text{collinear}\\ -1&,\mathbf u\times\mathbf v<0&&\text{clockwise}\\ \end{cases} $$ > **Polar Order**: `polarOrder(u, v, [o]) =` $$ \begin{cases} -1&,LHS<RHS\\ \ \ \ 0&,LHS=RHS\\ +1&,LHS>RHS\\ \end{cases}\\ \text{for }\begin{cases} LHS = tuple(sideY(u-w)&, 0&, sq(u-w))\\ RHS = tuple(sideY(v-w)&, cross(u-w, v-w)&, sq(v-w))\\ \end{cases} $$ `Default:` $\mathbf w = \mathbf 0$ > **Counter-Clockwise Direction**: `isCounterClockwise(u, v) = true` `ccw(u,v)` $$ \Leftrightarrow \measuredangle(\mathbf{u},\mathbf{v})\in(0^\circ,180^\circ) \Leftrightarrow\mathbf u\times\mathbf v>0 $$ > **Collinear Direction**: `isColinear(u, v) = true` `cln(u,v)` $$ \Leftrightarrow \exists k\in\mathbb{R},\mathbf u=k\mathbf v \Leftrightarrow\mathbf u\times\mathbf v=0 $$ > **Clockwise Direction**: `isClockwise(u,v) = isReflexAngle(u, v) = true` `cw(u,v)` $$ \Leftrightarrow \measuredangle(\mathbf{u},\mathbf{v})\in(180^\circ,360^\circ) \Leftrightarrow\mathbf u\times\mathbf v<0 $$ > **Unoriented Direction**: `isUnoriented(u, v) = true` $$ \Leftrightarrow \mathbf u=\mathbf v=\mathbf 0 $$ --- --- --- --- --- ## <center> F. Cài đặt </center> --- ### <center> F.1) Nhập xuất khởi tạo </center> ```cpp= template<class scalar> class vector2D { scalar x, y; ... }; using Point = vector2D<int> ``` > **Default Initialization**: > `Constructor `==`vector2D()`== > ```cpp > : x(0), y(0) {} > ``` > **Initialize from uniform scalar**: > `Constructor `==`vector2D(scalar x, scalar y)`== > ```cpp > : x(x), y(y) {} > ``` > **Initialize from non-uniform scalar**: > `Constructor `==`vector2D(scalar x, scalar y)`== ```cpp template<typename LHS, typename RHS, typename T = typename conditional <is_integral<LHS>::value&&is_integral<RHS>::value,long long,double>::type> vector2D<T> makeVector2D(const LHS& x, const RHS& y) { return vector2D<T>(static_cast<T>(x), static_cast<T>(y)); } ``` > **Initialize from vector**: > `Assignment Operator`==`vector = other_vector`== > ```cpp > { x = other.x; y = other.y; } > ``` > **Memory Free**: > `Destructor `==`~vector2D()`== > ```cpp > { delete x; delete y; } > ``` > **Input (cin)**: `Insertion Operator`==`>> vector`==`↦ &istream cin` > ```cpp > { return cin >> x >> y, cin; } > ``` > **Output (cout, cerr)**: `Extraction Operator`==`<< vector`==`↦ &ostream cout` > ```cpp > { return cout << "(" << x << "; " << y << ")", cout; } > ``` > `Note:` Nếu muốn tạo luồng cerr và cout khác nhau thì > ```cpp > if (cout.rdbuf() == cerr.rdbuf()) { /// cerr > cout << "(" << u.x << "; " << u.y << ")"; > } else { /// cout > cout << u.x << " " << u.y; > } > return cout; > ``` --- ### <center> F.2) Toán tử so sánh </center> --- #### <center> F.2.a) Toán tử kiểm tra vector 0 </center> > **Non-zero Check**: > `Explixit Bool: `==`(vector)`==`↦ boolean` > ```cpp > { return !isZero(); } > ``` > **Zero Check**: > `Exclamation Operator: `==`!vector`==`↦ boolean` > ```cpp > { return isZero(); } > ``` --- #### <center> F.2.b) So sánh vector theo góc quay </center> > **Less Than Operator**: > `Less Than Operator: `==`vector < other_vector`==`↦ bool` > ```cpp > { return polarOrder(vector, other_vector); } > ``` > **Equal To Operator**: > `Equal To Operator: `==`vector <= other_vector`==`↦ bool` > ```cpp > { return isEqual(vector.x, other_vector.x) > && isEqual(vector.y, other_vector.y); } > ``` > **Less Than or Equal To Operator**: > `Less Than or Equal To Operator: `==`vector <= other_vector`==`↦ bool` > ```cpp > { return (u < v) || (u == v); } > ``` > **Not Equal To**: > `Not Equal To Operator: `==`vector >= other_vector`==`↦ bool` > ```cpp > { return !(u = v); } > ``` > **Greater Than or Equal To Operator**: > `Greater Than or Equal To Operator: `==`vector >= other_vector`==`↦ bool` > ```cpp > { return !(u < v); } > ``` > **Greater Than Operator**: > `Greater Than Operator: `==`vector > other_vector`==`↦ bool` > ```cpp > { return !(u <= v); } > ``` --- ### <center> F.3) Toán tử biến đổi vector </center> --- #### <center> F.3.a) Symmetry Reflection </center> > **Vector Itself**: > `Unary Plus Operator:`==`+vector`==`↦ vector` > ```cpp > { return *this; } > ``` > **Vector Symmetry Reflection**: > `Unary Minus Operator:`==`-vector`==`↦ vector` > ```cpp > { return negation(); } > ``` > **Vector Coordinate Swap**: > `Logical NOT Operator`==`~vector`==`↦ vector` > ```cpp > { return reversion(); } > ``` --- #### <center> F.3.b) Translating </center> > **Vector Sumation**: > `Addition Operator:`==`vector + vector`==`↦ vector` > ```cpp > { return translate(+vector); } > ``` > **Vector Difference**: > `Subtraction Operator:`==`vector - vector`==`↦ vector` > ```cpp > { return translate(-vector); } > ``` > **Translating**: > `Addition Assignment Operator:`==`vector += vector`==`↦ &vector` > ```cpp > { return *this = translate(+vector); } > ``` > **Reverse Translating**: > `Subtraction Assignment Operator:`==`vector -= vector`==`↦ &vector` > ```cpp > { return *this = translate(-vector); } > ``` > **Vector Horizontal Slide**: > `Pre-increment Operator: `==`++vector`==`↦ &vector` > ```cpp > { return *this = translate(+1, 0); } > ``` > **Vector Horizontal Reverse Slide**: > `Pre-decrement Operator: `==`--vector`==`↦ &vector` > ```cpp > { return *this = translate(-1, 0); } > ``` > **Vector Vertical Slide**: > `Post-increment Operator: `==`vector++`==`↦ &vector` > ```cpp > { return *this = translate(0, +1); } > ``` > **Vector Vertical Reverse Slide**: > `Post-decrement Operator: `==`vector--`==`↦ &vector` > ```cpp > { return *this = translate(0, -1); } > ``` `Note:` `Post-* Operator` có thể trả về `&vector` https://ideone.com/HRgB56 --- #### <center> F.3.c) Scaling </center> > **Stretched Vector**: > `LHS Multiplication Operator:`==`vector * scalar`==`↦ vector` > `RHS Multiplication Operator:`==`scalar * vector`==`↦ vector` > ```cpp > { return scale(scalar); } > ``` > **Stretching**: > `Multiplication Assignment Operator: `==`vector *= scalar`==`↦ &vector` > ```cpp > { return *this = scale(scalar); } > ``` > **Squashed Vector**: > `LHS Division Operator: `==`vector / scalar`==`↦ vector` > ```cpp > { return scale(1 / scalar); } > ``` > **Reciprocal Squashed Vector**: > `RHS Division Operator: `==`scalar / vector`==`↦ vector` > ```cpp > { return reciprocal().scale(scalar); } > ``` > `Note:` Trùng với vector division nếu xem vector như một multivector > **Squashing**: > `Division Assignment Operator: `==`vector /= scalar`==`↦ &vector` > ```cpp > { return *this = scale(1 / scalar); } > ``` --- #### <center> F.3.d) Wrapping </center> > **Clamped Vector**: > `Logical AND Operator`==`vector & other_vector`==`↦ vector` > ```cpp > { return clamp(other_vector.x, other_vector.y); } > ``` > **Clamping**: > `Logical AND Assignment Operator`==`vector &= other_vector`==`↦ vector` > ```cpp > { return *this = clamp(other_vector.x, other_vector.y); } > ``` > **Wrapped Vector**: > `LHS Modulo Operator: `==`vector % scalar`==`↦ vector` > ```cpp > { return vector2D(scalar % x, scalar % y); } > ``` > **Reversed Wrapped Vector**: > `RHS Modulus Operator: `==`scalar % vector`==`↦ vector` > ```cpp > { return vector2D(x % scalar, y % scalar); } > ``` > **Wrapping**: > `Modulo Assignment Operator: `==`vector %= scalar`==`↦ &vector` > ```cpp > { return *this = vector2D(x % scalar, y % scalar); } > ``` --- ### <center> F.4) Toán tử số học với vector </center> > **Vector Horizontal Position**: > `Overloading Operator`==`vector[0]`==`↦ &scalar` > ```cpp > { return vector.x; } > ``` > **Vector Vertical Position**: > `Overloading Operator`==`vector[1]`==`↦ &scalar` > ```cpp > { return vector.y; } > ``` > **Dot Product/Inner Product**: > `Multiplication Operator`==`vector * other_vector`==`↦ scalar` > `Logical OR Operator`==`vector | other_vector`==`↦ scalar` > ```cpp > { return dot(*this, other_vector); } > ``` > **Perp Dot Product/2D Wedge Product/2D Cross Product**: > `Remainder Operator`==`vector % other_vector`==`↦ scalar` > `Logical XOR Operator`==`vector ^ other_vector`==`↦ scalar` > ```cpp > { return perp(*this, other_vector); } > ``` > **Vector Dilation Ratio**: > `Division Operator`==`vector / other_vector`==`↦ scalar` > ```cpp > { return dilation(*this, other_vector); } > ``` > **Vector Distance**: > `Shift Right Operator`==`vector >> other_vector`==`↦ scalar` > ```cpp > { return euclideanDistance(*this, other_vector); } > ``` > **Vector Squared Distance**: > `Shift Left Operator`==`vector << other_vector`==`↦ scalar` > ```cpp > { return squaredDistance(*this, other_vector); } > ``` --- ## <center> Z. Footnote </center> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .