Vector Algebra







A. Giới thiệu


A.1) Đối tượng độc giả


A.2) Thông tin khác






B. Không gian
R2

Kí hiệu

R2 là tập hợp:

R2={u=(x;y)x,yR}

Khi đó

R2 là không gian vector

Mọi

u=(x;y)R2 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
ϕR

Góc radian giữa
2
vector
θR

Đại số vô hướng
α,βR

Sai số
εR

Scalar
ux,uy,vx,vy,wx,wyR

Vector
u=(ux;uy),v=(vx;vy),w=(wx;wy)R2


B.1) Tính chất vector cơ bản

Definition:

vector u=(ux; uy)R2scalar ux,uyR

Zero Vector:

0=(0;0)!u=0u=0
Unit Vector:
u0

u^=(sin(θ); cos(θ))=uu

Basis Vector
i=i^=(1;0)j=j^=(0;1)

Additive Identity:
0+u=u+0=u

Additive Inverse:
u+(u)=0

Double Negation:
(u)=u

Associativity:
(αβ)u=α(βu)=β(αu)(u±v)±w=u±(v±w)

Commutativity:
u±v=v±u

Multiplicative Identity:
α×u=(αux; αuy)

Distributivity:
α(u±v)=αu±αv(α±β)u=αu±βu

Norm Property:

{u0u=0u=0{uv0uv=0u=v


B.2) Tính chất tích vô hướng (u⋅v) / tích chấm vuông (u⊥v)

Dot Product Definition:

uv=ux×vx+uy×vy
Perp Dot Product Definition:
uv=uxvyuyvx

Perp Dot Relationship:
perp2D(u,v)=wedge2D(u,v)=cross2D(u,v)

Note: Chỉ tồn tại ở không gian

2D

Nilpotent Property:

0u=u0=0uu=0
Squared Norm:
uu=u2

Associativity:
α(uv)=(αu)v=u(αv)α(uv)=(αu)v=u(αv)

Basis Vector:
i^j^=0i^j^=1

Commutativity:
uv=vuuv=vu

Anticommutativity:
uv=vu

Multiplicative Distributivity:
u(v±w)=uv±uwu(v±w)=uv±uw

Perpendicularity:
uvuv=0

Parallelity:
uvuv=0

Squared Product:
(u±v)(u±v)=(uu+vv)±2uv(u+v)(uv)=uuvv


B.3) Tính chất tích chéo (u×v) / tích ngoại (u∧v)

Cross Product Definition:

cross3D(u,v)=u×v=(uyvzuzvyuzvxuxvzuxvyuyvx)cross2D(u,v)=u×v=(uxvyuyvx)z^
Wedge Product Definition:
uv=uvsin(θ)n^

Cross Product Relationship
wedge3D(u,v)=cross3D(u,v)perp2D(u,v)=wedge2D(u,v)=cross2D(u,v)

Note: Ở không gian

2D
3D
thì tích chéo
u×v
cũng chính là tích ngoại
uv
(nếu coi
e1,e2,e3
trực chuẩn nhau)

Note: Tích chéo không tồn tại ở

1D
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.
wedge1D(u,v)=0

Linearity:

(αu+βv)w=α(uw)+β(vw)
Multiplicative Identity:
1×u=u×1=u

Nilpotent Property:
0×u=u×0=0u×u=0

Associativity:
α(u×v)=(αu)×v=u×(αv)

Basis Vector
i^×j^=1

Anticommutativity:
u×v=v×u

Multiplicative Distributivity:
u×(v±w)=(u×v)±(u×w)


B.5) Tính chất tích hình học (uv) và [u,v]

Geometric Product Definition:

uv=uv+uv
Commutator Product Definition:
vu=[u,v]=uvuv

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

u & v=vector2D(uv; vu)

Symmetric:

uv=12(uv+vu)
Antisymmetric:
uv=12(uvvu)

Associativity:
(uv)w=u(vw)

Left Distributivity:
u(v±w)=uv±uw

Right Distributivity:
(u±v)w=uw+vw

Contraction:
u2=uu=u2

Inversion:
u1=uu2

Division:
uv=uvv2

Identity:
(uv+vu)=(u+v)2(u2+v2)


B.6) Tính chất giữa các phép nhân

wedge3D(u,v)=cross3D(u,v)perp2D(u,v)=wedge2D(u,v)=cross2D(u,v)

Unit Vector:

u^×v^2sin2θ+(u^v^)2cos2θ=u^=v^=1i^j^=i^×j^=i^×j^=1
Norm Property:
{u×v=uv=uvsinθ0u×v=0[u=0v=0uv

Jacobi Identity:
u×(v×w)+v×(w×u)+w×(u×v)=0

Associativity/Scalar Triple Product:
u(v×w)=w(u×v)=v(w×u)

Lagrange Identity:
(a×b)(c×d)=(ac)(bd)(ad)(bc)uv2=u×v2=u2v2(uv)2

Product-Product Relation:
u×v=(uv)z^uv=uv

Product-Angle Relation:
u×vuv=uvsin(θ)uvcos(θ)=tan(θ)u×vuv=uvuv=sin(θ)uvuv=cos(θ)

Cosine Law:
{u±v2=u2±2uvcos(θ)+v2θ=(u,v)

Pythagore Identity:
uv=0u±v2=u2+v2u2=(uv^)2+u(uv^)v^2

B.C.S Inequality (Bunhiacopxki-Cauchy-Schwarz):
uvuv

Triangle Inequality:
u+vu+v

Reversed Triangle Inequality:
uvuv

Extended Triangle Inequality:
uwuv+vw






C. Hàm tiện ích


C.1) Hàm tiện ích chuyển đổi hệ

Casterian ↦ Polar: toPolar(u) =

pair(r; θ)=pair(ux2+uy2; atan2(y,x))=pair(magu; polaru)
Note: pair(r, θ) không nhất thiết phải cùng kiểu dữ liệu

Polar ↦ Casterian: toCasterian(r, θ) =

vector2D(ux,uy)=vector2D(rcos(θ); rsin(θ))


C.2) Hàm tiện ích radian

Radian ↦ Radian[0, 2π): radNorm(radian θ) =

((θ % 2π)+2π) % 2π
Radian ↦ Degree: radToDeg(radian θ) =
deg(radian θ) =
θ2π×360

Radian ↦ Hour: radToHour(radian θ) =
θ2π×24h

Radian ↦ Minute: radToMinute(radian θ) =
θ2π×1440m

Radian ↦ Second: radToSecond(radian θ) =
θ2π×86400s

Radian ↦ Clock[0h,24h): radToClock(radian θ) =
vector(hour,minute,second,nsf)for{hour=toHour(toNormRad(θ)) % 24minute=toMinute(toNormRad(θ)) % 60second=toSecond(toNormRad(θ)) % 60nsf=(toSecond(toNormRad(θ))second)÷109

Note: nsf = nanosecond fraction (but converted to integer)
Clock[0h,24h) ↦ Radian[0, 2π): clockToRad(hour, minute, second, nsf) =
2π×(hour24+minute1440+second86400+nsf86400109)

Default:
hour:=0,minute:=0,second:=0,nsf:=0


C.3) Hàm tiện ích degree

Degree ↦ Degree[0°, 360°): degNorm(degree ϕ) =

((θ % 360°)+360°) % 360°
Degree ↦ Radian: degToRad(degree ϕ) =
rad(degree ϕ) =
ϕ360×2π

Degree ↦ Hour: degToHour(degree ϕ) =
ϕ360×24h

Degree ↦ Minute: degToMinute(degree ϕ) =
ϕ360×1440m

Degree ↦ Second: degToSecond(degree ϕ) =
ϕ360×86400s

Degree ↦ Clock[0h,24h): degToClock(radian ϕ) =
vector(hour,minute,second,nanosecond)for{hour=toHour(toNormDeg(ϕ)) % 24minute=toMinute(toNormDeg(ϕ)) % 60second=toSecond(toNormDeg(ϕ)) % 60nanosecond=toSecond(toNormDeg(ϕ))second

Clock[0h,24h) ↦ Degree[0°, 360°): clockToRad(hour, minute, second, nsf) =
360×(hour24+minute1440+second86400+nsf86400109)

Default:
hour:=0,minute:=0,second:=0,nsf:=0


C.4) Hàm tiện ích số phức

Vector ↦ Complex:
toComplex(u) = cplx(u) =

complex(ux; uy)
Vector * Vector ↦ Complex:
complexMultiplication(u, v) = mul(u, v) =
uv=complex(uxvxuyvy;uxvy+uyvx)

Vector / Vector ↦ Complex:
complexDivision(u, v) = div(u, v) =
u÷v=complex(uvv; v×uv)=complex(uxvx+uyvyuy2+vy2; uyvxuxvyuy2+vy2)


C.5) Hàm tiện ích chỉ hướng

Quadrant Function:
quadrantValue(u) =

{4,ux=0uy>0phần âm trục tung Oy3,ux<0uy=0phần âm trục hoành Ox2,ux=0uy>0phần dương trục tung Oy+1,ux>0uy=0phần dương trục hoành Ox+   0,ux=0uy=0gốc toạ độ O(0;0)+1,ux>0uy>0góc phần tư thứ I+2,ux<0uy>0góc phần tư thứ II+3,ux<0uy<0góc phần tư thứ III+4,ux>0uy<0góc phần tư thứ IV
quadrantString(u) =
{"Negative Vertical Axis",ux=0uy>0"Negative Horizontal Axis",ux<0uy=0"Positive Vertical Axis",ux=0uy>0"Positive Horizontal Axis",ux>0uy=0"Origin Position",ux=0uy=0"First Quadrant",ux>0uy>0"Second Quadrant",ux<0uy>0"Third Quadrant",ux<0uy<0"Fourth Quadrant",ux>0uy<0

Angularity Function:
angularityValue(u, v, [θ]) =
{3,x=y=0u có góc bất định với v2,x>y=0u tạo thành góc không với v1,xy>0u tạo thành góc nhọn với    0,yx=0u tạo thành góc vuông với v+1,xy<0u tạo thành góc tù với +2,x<y=0u tạo thàng góc thẳng với v+3,xy=NaNu không có góc xác định với vvới{x=(ux+vx)cos(θ)(uy+vy)sin(θ)y=(ux+vx)sin(θ)+(uy+vy)cos(θ)

angularityString(u, v, [θ]) =
{"Ambiguous Angle",x=y=0u có góc bất định với v"Zero Angle",x>y=0u tạo thành góc không với v"Acute Angle",xy>0u tạo thành góc nhọn với "Right Angle",yx=0u tạo thành góc vuông với v"Obtuse Angle",xy<0u tạo thành góc tù với "Complete Angle",x<y=0u tạo thàng góc thẳng với v"Invalid Angle",xy=NaNu không có góc xác định với vvới{x=(ux+vx)cos(θ)(uy+vy)sin(θ)y=(ux+vx)sin(θ)+(uy+vy)cos(θ)

Default:
θ:=π2=90

Relative Direction:
relativeValue(u, v, [θ]) =
{4,x=0y>0u vuông góc bên phải với v3,x<0y=0u ngược hướng song song với v2,x=0y>0u vuông góc bên trái với v1,x>0y=0u cùng hướng song song với v   0,x=0y=0u trùng với v+1,x>0y>0u tạo thành góc nhọn, hướng sang bên trái+2,x<0y>0u tạo thành góc tù, hướng sang bên trái+3,x<0y<0u tạo thành góc tù, hướng sang bên phải+4,x>0y<0u tạo thành góc nhọn, hướng sang bên phảivới{x=(ux+vx)cos(θ)(uy+vy)sin(θ)y=(ux+vx)sin(θ)+(uy+vy)cos(θ)

relativeString(u, v, [θ]) =
{"Right-hand Perpendicular",x=0y>0"Parallel",x<0y=0"Left-hand Perpendicular",x=0y>0"Antiparallel",x>0y=0"Equivalent",x=0y=0"Left-hand Acute",x>0y>0"Left-hand Obtuse",x<0y>0"Right-hand Obtuse",x<0y<0"Right-hand Acute",x>0y<0với{x=(ux+vx)cos(θ)(uy+vy)sin(θ)y=(ux+vx)sin(θ)+(uy+vy)cos(θ)

Default:
θ:=0

Cardinal Direction:
cardinalValue(u) =
{1,(ux=uy=0)0,(1π/4θ<3π/4)1,(3π/4θ<5π/4)2,(5π/4θ<7π/4)3,(7π/4θ<8π/4)(0π/4θ<1π/4)

cardinalString(u) =
{"Center",(ux=uy=0)"East",(7π/4θ<8π/4)(0π/4θ<1π/4)"North",(1π/4θ<3π/4)"West",(3π/4θ<5π/4)"South",(5π/4θ<7π/4)

Intercardinal/Ordinal Direction:
ordinalValue(u) =
{1,(ux=uy=0)0,(15π/8θ<16π/8)(0π/8θ<1π/8)1,(1π/8θ<3π/8)2,(3π/8θ<5π/8)3,(5π/8θ<7π/8)4,(7π/8θ<9π/8)5,(9π/8θ<11π/8)6,(11π/8θ<13π/8)7,(13π/8θ<15π/8)

ordinalString(u) =
{"Center",(ux=uy=0)"East",(15π/8θ<16π/8)(0π/8θ<1π/8)"Northeast",(1π/8θ<3π/8)"North",(3π/8θ<5π/8)"Northwest",(5π/8θ<7π/8)"West",(7π/8θ<9π/8)"Southwest",(9π/8θ<11π/8)"South",(11π/8θ<13π/8)"Southeast",(13π/8θ<15π/8)

Halfwin Direction:
halfwindValue(u) =
{1,(ux=uy=0)0,(31π/16θ<32π/16)(0π/16θ<1π/16)1,(1π/16θ<3π/16)2,(3π/16θ<5π/16)3,(5π/16θ<7π/16)4,(7π/16θ<9π/16)5,(9π/16θ<11π/16)6,(11π/16θ<13π/16)7,(13π/16θ<15π/16)8,(15π/16θ<17π/16)9,(17π/16θ<19π/16)10,(19π/16θ<21π/16)11,(21π/16θ<23π/16)12,(23π/16θ<25π/16)13,(25π/16θ<27π/16)14,(27π/16θ<29π/16)15,(29π/16θ<31π/16)

halfwindString(u) =
{"Center",(ux=uy=0)"East",(31π/16θ<32π/16)(0π/16θ<1π/16)"Northeast by East",(1π/16θ<3π/16)"Northeast",(3π/16θ<5π/16)"North by Northeast",(5π/16θ<7π/16)"North",(7π/16θ<9π/16)"North by Northwest",(9π/16θ<11π/16)"Northwest",(11π/16θ<13π/16)"Northwest by West",(13π/16θ<15π/16)"West",(15π/16θ<17π/16)"West by Southwest",(17π/16θ<19π/16)"Southwest",(19π/16θ<21π/16)"South by Southwest",(21π/16θ<23π/16)"South",(23π/16θ<25π/16)"South by Southeast",(25π/16θ<27π/16)"Southeast",(27π/16θ<29π/16)"Southeast by East",(29π/16θ<31π/16)

Quarterwin Direction:
quarterwindValue(u) =
{1,(ux=uy=0)0,(63π/32θ<64π/32)(0π/32θ<1π/32)1,(1π/32θ<3π/32)2,(3π/32θ<5π/32)3,(5π/32θ<7π/32)4,(7π/32θ<9π/32)5,(9π/32θ<11π/32)6,(11π/32θ<13π/32)7,(13π/32θ<15π/32)8,(15π/32θ<17π/32)9,(17π/32θ<19π/32)10,(19π/32θ<21π/32)11,(21π/32θ<23π/32)12,(23π/32θ<25π/32)13,(25π/32θ<27π/32)14,(27π/32θ<29π/32)15,(29π/32θ<31π/32)16,(31π/32θ<33π/32)17,(33π/32θ<35π/32)18,(35π/32θ<37π/32)19,(37π/32θ<39π/32)20,(39π/32θ<41π/32)21,(41π/32θ<43π/32)22,(43π/32θ<45π/32)23,(45π/32θ<47π/32)24,(47π/32θ<49π/32)25,(49π/32θ<51π/32)26,(51π/32θ<53π/32)27,(53π/32θ<55π/32)28,(55π/32θ<57π/32)29,(57π/32θ<59π/32)30,(59π/32θ<61π/32)31,(61π/32θ<63π/32)

quarterwindString(u) =
{"Center",(ux=uy=0)"East",(63π/32θ<64π/32)(0π/32θ<1π/32)"East by North",(1π/32θ<3π/32)"East-Northeast",(3π/32θ<5π/32)"Northeast by East",(5π/32θ<7π/32)"Northeast",(7π/32θ<9π/32)"Northeast by North",(9π/32θ<11π/32)"North-Northeast",(11π/32θ<13π/32)"North by East",(13π/32θ<15π/32)"North",(15π/32θ<17π/32)"North by West",(17π/32θ<19π/32)"North-Northwest",(19π/32θ<21π/32)"Northwest by North",(21π/32θ<23π/32)"Northwest",(23π/32θ<25π/32)"Northwest by West",(25π/32θ<27π/32)"West-Northwest",(27π/32θ<29π/32)"West by North",(29π/32θ<31π/32)"West",(31π/32θ<33π/32)"West by South",(33π/32θ<35π/32)"West-Southwest",(35π/32θ<37π/32)"Southwest by West",(37π/32θ<39π/32)"Southwest",(39π/32θ<41π/32)"Southwest by South",(41π/32θ<43π/32)"South-Southwest",(43π/32θ<45π/32)"South by West",(45π/32θ<47π/32)"South",(47π/32θ<49π/32)"South by East",(49π/32θ<51π/32)"South-Southeast",(51π/32θ<53π/32)"Southeast by South",(53π/32θ<55π/32)"Southeast",(55π/32θ<57π/32)"Southeast by East",(57π/32θ<59π/32)"East-Southeast",(59π/32θ<61π/32)"East by South",(61π/32θ<63π/32)


C.6) Biểu tượng

quadrantSymbol(u) =

{'⍖',ux=0uy>0phần âm trục tung Oy'⍅',ux<0uy=0phần âm trục hoành Ox'⍏',ux=0uy>0phần dương trục tung Oy+'⍆',ux>0uy=0phần dương trục hoành Ox+'⨁',ux=0uy=0gốc toạ độ O(0;0)'Ⅰ',ux>0uy>0góc phần tư thứ I'Ⅱ',ux<0uy>0góc phần tư thứ II'Ⅲ',ux<0uy<0góc phần tư thứ III'Ⅳ',ux>0uy<0góc phần tư thứ IV
angularitySymbol(u, v, [θ]) =
{'𐽗',x=y=0u có góc bất định với v'⥉',x>y=0u tạo thành góc không với v'⦟',xy>0u tạo thành góc nhọn với '⦜',yx=0u tạo thành góc vuông với v'⦦',xy<0u tạo thành góc tù với '⥈',x<y=0u tạo thàng góc thẳng với v'∅',xy=NaNu không có góc xác định với vvới{x=(ux+vx)cos(θ)(uy+vy)sin(θ)y=(ux+vx)sin(θ)+(uy+vy)cos(θ)

relativeSymbol(u, v, [θ]) =
{'⍆',x=0y>0u vuông góc bên phải với v'⇅',x<0y=0u ngược hướng song song với v'⍅',x=0y>0u vuông góc bên trái với v'⇈',x>0y=0u cùng hướng song song với v'≡',x=0y=0u trùng với v'⦭',x>0y>0u tạo thành góc nhọn, hướng sang bên trái'⦯',x<0y>0u tạo thành góc tù, hướng sang bên trái'⦮',x<0y<0u tạo thành góc tù, hướng sang bên phải'⦬',x>0y<0u tạo thành góc nhọn, hướng sang bên phảivới{x=(ux+vx)cos(θ)(uy+vy)sin(θ)y=(ux+vx)sin(θ)+(uy+vy)cos(θ)

cardinalSymbol(u) =
{'◆',(ux=uy=0)'⮙',(1π/4θ<3π/4)'⮘',(3π/4θ<5π/4)'⮛',(5π/4θ<7π/4)'⮚',(7π/4θ<8π/4)(0π/4θ<1π/4)

ordinalSymbol(u) =
{'◆',ux=uy=0'⮚',(15π/8θ<16π/8)(0π/8θ<1π/8)'⬈',(1π/8θ<3π/8)'⮙',(3π/8θ<5π/8)'⬉',(5π/8θ<7π/8)'⮘',(7π/8θ<9π/8)'⬋',(9π/8θ<11π/8)'⮛',(11π/8θ<13π/8)'⬊',(13π/8θ<15π/8)

halfwindSymbol(u) =
{'◆',(ux=uy=0)'⮚',(31π/16θ<32π/16)(0π/16θ<1π/16)'⮫',(1π/16θ<3π/16)'⬈',(3π/16θ<5π/16)'⮭',(5π/16θ<7π/16)'⮙',(7π/16θ<9π/16)'⮬',(9π/16θ<11π/16)'⬉',(11π/16θ<13π/16)'⮪',(13π/16θ<15π/16)'⮘',(15π/16θ<17π/16)'⮨',(17π/16θ<19π/16)'⬋',(19π/16θ<21π/16)'⮮',(21π/16θ<23π/16)'⮛',(23π/16θ<25π/16)'⮯',(25π/16θ<27π/16)'⬊',(27π/16θ<29π/16)'⮩',(29π/16θ<31π/16)

quarterwindSymbol(u) =
{"◆",(ux=uy=0)"⮚",(63π/32θ<64π/32)(0π/32θ<1π/32)"⮫-",(1π/32θ<3π/32)"⮫",(3π/32θ<5π/32)"⮫+",(5π/32θ<7π/32)"⬈",(7π/32θ<9π/32)"⮭-",(9π/32θ<11π/32)"⮭",(11π/32θ<13π/32)"⮭+",(13π/32θ<15π/32)"⮙",(15π/32θ<17π/32)"⮬-",(17π/32θ<19π/32)"⮬",(19π/32θ<21π/32)"⮬+",(21π/32θ<23π/32)"⬉",(23π/32θ<25π/32)"⮪-",(25π/32θ<27π/32)"⮪",(27π/32θ<29π/32)"⮪+",(29π/32θ<31π/32)"⮘",(31π/32θ<33π/32)"⮨-",(33π/32θ<35π/32)"⮨",(35π/32θ<37π/32)"⮨+",(37π/32θ<39π/32)"⬋",(39π/32θ<41π/32)"⮮-",(41π/32θ<43π/32)"⮮",(43π/32θ<45π/32)"⮮+",(45π/32θ<47π/32)"⮛",(47π/32θ<49π/32)"⮯-",(49π/32θ<51π/32)"⮯",(51π/32θ<53π/32)"⮯+",(53π/32θ<55π/32)"⬊",(55π/32θ<57π/32)"⮩-",(57π/32θ<59π/32)"⮩",(59π/32θ<61π/32)"⮩+",(61π/32θ<63π/32)






D. Hàm tính toán


D.1) Hàm tính giá trị thông dụng

Zero Check: u.isZero() = true
⇔ is0(u) = true

u=0{ux=0uy=0

Horizontal Position: u.horizontal() =
u.x() =

ux

Vertical Position: u.vertical() =
u.y() =

uy

Norm: u.norm(p) =
norm(u, p) =

up=(|ux|p+|uy|p)(1/p)
Default:
p:=2

Length/Abs: u.length() = u.abs() =
len(u) = abs(u) =

u=ux2+uy2
Squared Length: u.squaredLength() =
sq(u)
ux2+uy2

Note: Thường dùng với số nguyên
Z
cho bớt sai số
Magnitude Position: u.r() = u.magnitude()
r(u) = mag(u) =
magu=u

Polar Angle: u.theta() = u.polarAngle() = polarAngle(u) =
theta(u) = polar(u) =
atan2(uy;ux)

Angle Between Vectors: u.angle(v) =
angle(u, v) =

θ=(atan2(u×v, uv)+π) % 2π
Interior Angle: u.interiorAngle(v) =
interior(u, v) =
θint=2πθext=cos1(uvuv)

Exterior Angle: u.exteriorAngle(v) =
exterior(u, v) =
θext=2πθint=sin1(u×vuv)

Manhattan/Taxicab Distance: manhattanDistance(u, v) =
u.taxicab(v) =
uvx=vux=uxvx+uyvy

Straight/Euclidean Distance: euclideanDistance(u, v)
u.dist(v) =
uv=vu=(uxvx)2+(uyvy)2

Squared Euclidean Distance: squaredDistance(u, v) =
u.sqdist(v)
uv2=vu2=(uxvx)2+(uyvy)2

Note: Không dùng công thức
dist(u,v)2
để tránh sai số


D.2) Hàm tính giá trị ít dùng

Scalar Projection: u.scalarProj(θ) = u.scalarProj(v) =

ucosθ=uvv=uxvx+uyvyvx2+vy2
Scalar Rejection: u.scalarRej(θ) = u.scalarRej(v) =
usinθ=uvv=uyvxuxvyvx2+vy2


D.3) Hàm tính vector

Vector Projection: u.vectorProjection(v) =
proj(u, v) =

projv(u)=uvv2×v=u^u.scalarProj(v)

Vector Rejection: u.vectorRejection(v) =
rej(u, v) =

rejv(u)=uvv2×v=uprojv(u)

Dot Product: u.dotProduct(v) =
dot(u, v) =

uv=ux×vx+uy×vy
Perp Dot Product: u.perpProduct(v) =
perp(u, v) =
uv=ux×vyuy×vx

2D Cross Product: u.crossProduct(v) =
cross(u, v) =
u×v=ux×vyuy×vx

Wedge Product: u.wedgeProduct(v)
wedge(u, v) =
uv=ux×vyuy×vx

Geometric & Commutator Product: u.geoProduct(v)
geomul(u, v) =
vector2D(uv; vu)

Vector Geometric Inverse: u.geoInverse()
geoinv(u) =
u1=uu2=u^u

Vector Geometric Division: u.geoDivision(v)
geodiv(u, v) =
uv=u(v1)=uvv2

Vector Cross Division: crossDivision(u×v, v, θ) =
u=u×vcot(θ)vv×(u×v)v2


D.4) Hàm biến đổi vector

D.4.a) Hàm biến đổi tuyến tính vector

Swap Transformation: u.swap(v)
Negation Transformation: u.negation() =

u=vector2D(ux; uy)
Conjugation Transformation: u.conjugation() =
u=vector2D(ux; uy)

Translation Transformation: u.translate(v) = u.translate(vx, vy) =

uu+v=vector2D(ux+vx; uy+vy)
Reversion Transformation: u.reverse() =
revu=vector2D(uy; ux)

Reflection Transformation: u.reflection(v) =
 Ref|v(u)=2projv(u)u=2uvv2vu

Mirror-X/Flip-Y Transformation: u.mirror_x() = u.flip_y() =
 R|(u)=vector2D(ux; uy)

Mirror-Y/Flip-X Transformation: u.mirror_y() = u.flip_x() =
 R   (u)=vector2D(ux; uy)

Mirror-XY/Flip-XY/Negation Transformation: u.mirror_xy() = u.flip_xy() = u.negation() =
 R(u)=vector2D(ux; uy)

Scale Transformation: u.scale(α, [β]) =
Scale (u,α,β)=vector2D(αux; βuy)

Default:
β:=α

Note:

Khi

[α=1,β>1α>1,β=1 thì gọi là hàm stretch (
)
Khi
[α<1,β=1α=1,β<1
thì gọi là hàm squash (
)
Khi
[α<1,β>1α>1,β<1
thì gọi là hàm squeeze (
↑↓
)

D.4.c) Hàm biến đổi khác

Unitization Transformation: u.unit() = u.normalized() =

u^=vector2D(uxu,uyu)
Note: Cẩn thận khi
u=0
, và cẩn thận nhầm với hàmnorm(u, p)
Reciprocity Transformation: u.reciprocal() =
recu=vector2D(1ux; 1uy)

Note: Cẩn thận khi
ux=0
hoặc
uy=0

Rotation Transformation: u.rotate(θ, [isClockwise]) =
{Rθ(u)=(uxcos(θ)uysin(θ); uycos(θ)+uxsin(θ)),isClockwise=falseRθ(u)=(uxcos(θ)+uysin(θ); uycos(θ)uxsin(θ)),isClockwise=true

Default:
θ:=π2
(quay
90
) và
isClockwise:=true
(quay cùng chiều kim đồng hồ)

Clamp Transformation: u.clamp(α, [β]) =

vector2D(sign(ux)min(|u.x|,|α|); sign(uy)min(|u.y|,|β|))
Default:
β:=α

Shear Transformation: u.shear(α, [β]) =
T↰↱shear(u,α,β)=vector2D(ux+αuy; uy+βux)

Default:
β:=0

Linear Transformation: u.shear(α1, α2, β1, β2) =
T(u,α1,α2,β1,β2)=vector2D(α1ux+α2uy; β1uy+β2ux)

Component-wise Transformation: u.componentwise(f) =
uf=vector2D(f(ux); f(uy))






E. Hàm kiểm tra


E.1) Kiểm tra tính bằng nhau

Sign Function:
sign(scalar x) =

[x>0][x<0]={+1,x>0  0,x=01,x<0
Note:
0
x
nên cùng kiểu dữ liệu, và dấu
[x=y]
iverson brackets
Note: Có thể xem quadrant() là sign function cho vector

Float Equality: isEqual(scalar u, scalar v, high-precision ε) = true

{|uxvx|ε|uyvy|ε
Default:
ε=109

Equality Function:
equalityValue(scalar x, scalar y) =
{9,|xy|1098,109<|xy|1087,108<|xy|1076,107<|xy|1065,106<|xy|1054,105<|xy|1043,104<|xy|1032,103<|xy|1021,102<|xy|101   0,xy


E.2) Kiểm tra tính trực giao

Orthogonal Check: isOrthogonal(u, v) = true

[uv=0u×v=0
Dilation Factor: u.dilation(v) =
{uxvx,(vxvy0)(uxvx=uyvyR)+,(uxvx=uyvy=+),(uxvx=uyvy=)NaN,(uyvy=NaN)(uxvx=NaN)(uyvy=NaN)(uxvxuyvy)

Collinear Check: isColinear(u, v) = true
k=dilation(u,v)u=kvu×v=0

Parallel Check: isParallel(u, v) = true
{u×v=0uv>0

Antiparallel Check: isAntiparallel(u, v) = true
{u×v=0uv<0

Zero Angle Check: isZeroAngle(u, v) = true
(u,v)=0θ=0uv=uv

Right Angle Check: isPerpendicular(u, v) = isRightAngle(u, v) = true
(u,v)=90θ=π2uvuv=0

Straight Angle Check: isStraightAngle(u, v) = true
(u,v)=180θ=πuv=uv


E.3) Kiểm tra góc xiên

Left-Right Side Indicator: sideX(u, [v]) =

{+1,uv>0same side   0,uv=0perpendicular1,uv<0opposite side
Default:
v=0side(u)=sign(uy)

Note: so với đường thẳng vuông góc với phương của
u

Top-Down Side Indicator: sideY(u, [v]) =
{+1,u×v>0same half   0,u×v=0collinear1,u×v<0opposite half

Default:
v=0

Note: so với đường thẳng đi qua
u

Acute Angle Check: isAcuteAngle(u, v) = true

(u,v)(0,90)0<θ<π2uv>0
Obtuse Angle Check: isObtuseAngle(u, v) = true
(u,v)(90,180)π2<θ<πuv<0

Reflex Angle Check: isReflexAngle(u, v) = !isReflexAngle(v, u) = true
(u,v)(180,0)π<θ<2πu×v<0


E.4) Hàm kiểm tra hướng góc

Orientability Function: orient(u, v) =

{+1,u×v>0counter-clockwise   0,u×v=0collinear1,u×v<0clockwise
Polar Order: polarOrder(u, v, [o]) =
{1,LHS<RHS   0,LHS=RHS+1,LHS>RHSfor {LHS=tuple(sideY(uw),0,sq(uw))RHS=tuple(sideY(vw),cross(uw,vw),sq(vw))

Default:
w=0

Counter-Clockwise Direction: isCounterClockwise(u, v) = true
ccw(u,v)
(u,v)(0,180)u×v>0

Collinear Direction: isColinear(u, v) = true
cln(u,v)
kR,u=kvu×v=0

Clockwise Direction: isClockwise(u,v) = isReflexAngle(u, v) = true
cw(u,v)
(u,v)(180,360)u×v<0

Unoriented Direction: isUnoriented(u, v) = true
u=v=0






F. Cài đặt


F.1) Nhập xuất khởi tạo

template<class scalar> class vector2D { scalar x, y; ... }; using Point = vector2D<int>

Default Initialization:
Constructor vector2D()

: x(0), y(0) {}

Initialize from uniform scalar:
Constructor vector2D(scalar x, scalar y)

: x(x), y(y) {}

Initialize from non-uniform scalar:
Constructor vector2D(scalar x, scalar y)

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 Operatorvector = other_vector

{ x = other.x; y = other.y; }

Memory Free:
Destructor ~vector2D()

{ delete x; delete y; }

Input (cin):
Insertion Operator>> vector↦ &istream cin

{ return cin >> x >> y, cin; }

Output (cout, cerr):
Extraction Operator<< vector↦ &ostream cout

{ return cout << "(" << x << "; " << y << ")", cout; }

Note: Nếu muốn tạo luồng cerr và cout khác nhau thì

if (cout.rdbuf() == cerr.rdbuf()) { /// cerr
    cout << "(" << u.x << "; " << u.y << ")";
} else { /// cout
    cout << u.x << " " << u.y;
}
return cout;

F.2) Toán tử so sánh


F.2.a) Toán tử kiểm tra vector 0

Non-zero Check:
Explixit Bool: (vector)↦ boolean

{ return !isZero(); }

Zero Check:
Exclamation Operator: !vector↦ boolean

{ return isZero(); }

F.2.b) So sánh vector theo góc quay

Less Than Operator:
Less Than Operator: vector < other_vector↦ bool

{ return polarOrder(vector, other_vector); }

Equal To Operator:
Equal To Operator: vector <= other_vector↦ bool

{ 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

{ return (u < v) || (u == v); }

Not Equal To:
Not Equal To Operator: vector >= other_vector↦ bool

{ return !(u = v); }

Greater Than or Equal To Operator:
Greater Than or Equal To Operator: vector >= other_vector↦ bool

{ return !(u < v); }

Greater Than Operator:
Greater Than Operator: vector > other_vector↦ bool

{ return !(u <= v); }

F.3) Toán tử biến đổi vector


F.3.a) Symmetry Reflection

Vector Itself:
Unary Plus Operator:+vector↦ vector

{ return *this; }

Vector Symmetry Reflection:
Unary Minus Operator:-vector↦ vector

{ return negation(); }

Vector Coordinate Swap:
Logical NOT Operator~vector↦ vector

{ return reversion(); }

F.3.b) Translating

Vector Sumation:
Addition Operator:vector + vector↦ vector

{ return translate(+vector); }

Vector Difference:
Subtraction Operator:vector - vector↦ vector

{ return translate(-vector); }

Translating:
Addition Assignment Operator:vector += vector↦ &vector

{ return *this = translate(+vector); }

Reverse Translating:
Subtraction Assignment Operator:vector -= vector↦ &vector

{ return *this = translate(-vector); }

Vector Horizontal Slide:
Pre-increment Operator: ++vector↦ &vector

{ return *this = translate(+1, 0); }

Vector Horizontal Reverse Slide:
Pre-decrement Operator: --vector↦ &vector

{ return *this = translate(-1, 0); }

Vector Vertical Slide:
Post-increment Operator: vector++↦ &vector

{ return *this = translate(0, +1); }

Vector Vertical Reverse Slide:
Post-decrement Operator: vector--↦ &vector

{ return *this = translate(0, -1); }

Note: Post-* Operator có thể trả về &vector https://ideone.com/HRgB56


F.3.c) Scaling

Stretched Vector:
LHS Multiplication Operator:vector * scalar↦ vector
RHS Multiplication Operator:scalar * vector↦ vector

{ return scale(scalar); }

Stretching:
Multiplication Assignment Operator: vector *= scalar↦ &vector

{ return *this = scale(scalar); }

Squashed Vector:
LHS Division Operator: vector / scalar↦ vector

{ return scale(1 / scalar); }

Reciprocal Squashed Vector:
RHS Division Operator: scalar / vector↦ vector

{ 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

{ return *this = scale(1 / scalar); }

F.3.d) Wrapping

Clamped Vector:
Logical AND Operatorvector & other_vector↦ vector

{ return clamp(other_vector.x, other_vector.y); }

Clamping:
Logical AND Assignment Operatorvector &= other_vector↦ vector

{ return *this = clamp(other_vector.x, other_vector.y); }

Wrapped Vector:
LHS Modulo Operator: vector % scalar↦ vector

{ return vector2D(scalar % x, scalar % y); }

Reversed Wrapped Vector:
RHS Modulus Operator: scalar % vector↦ vector

{ return vector2D(x % scalar, y % scalar); }

Wrapping:
Modulo Assignment Operator: vector %= scalar↦ &vector

{ return *this = vector2D(x % scalar, y % scalar); }

F.4) Toán tử số học với vector

Vector Horizontal Position:
Overloading Operatorvector[0]↦ &scalar

{ return vector.x; }

Vector Vertical Position:
Overloading Operatorvector[1]↦ &scalar

{ return vector.y; }

Dot Product/Inner Product:
Multiplication Operatorvector * other_vector↦ scalar
Logical OR Operatorvector | other_vector↦ scalar

{ return dot(*this, other_vector); }

Perp Dot Product/2D Wedge Product/2D Cross Product:
Remainder Operatorvector % other_vector↦ scalar
Logical XOR Operatorvector ^ other_vector↦ scalar

{ return perp(*this, other_vector); }

Vector Dilation Ratio:
Division Operatorvector / other_vector↦ scalar

{ return dilation(*this, other_vector); }

Vector Distance:
Shift Right Operatorvector >> other_vector↦ scalar

{ return euclideanDistance(*this, other_vector); }

Vector Squared Distance:
Shift Left Operatorvector << other_vector↦ scalar

{ return squaredDistance(*this, other_vector); }

Z. Footnote

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.