P3
Vector: Basics
定义
An (Euclidean) vector: A geometric entity endowed with magnitude and direction.
P=[pxpypz]∈R3
o=[000]
The vector p is defined with respect to the origin o.
坐标系
✅ 用黑来区分,矢量:黑体小写;标量:斜体;矩阵:黑体大写;
P4
The choice of a right-hand or left-hand system is largely due to:
the convention of the screen space.
✅ 左手坐标系,E轴正方向朝屏幕内,好处是物体坐标 x、y、z 都是正值。右手系统的物体都在E轴负方向。
P5
Stacked Vector
Vectors can be stacked up to form a high-dimensional vector, commonly used for describing the state of an object.
Not a geometric vector,but a stacked vector.
P6
Vector Arithematic: Addition and Subtraction
p±q=[px±qxpy±qypz±qz]
p+q=q+p
Addition is commutative. |
---|
Geometric Meanings |
---|
P7
Example 1: Linear Representation
A (geometric) vector can represent a position, a velocity, a force, or a line/ray/segment.
✅ 图2。同一个公式,对t做不同的约束,可以定义不同的东西。
P(t) 是 P 和 q 的 blend
P8
Vector Norm
A vector norm measures the magnitude of a vector: its length.
✅ L1-Norm 又称为曼哈顿的距离。没写下标一般默认L2-Norm
P9
Vector Norm: Usage
Distance between q and p: ||q−p||
A unit vector:
||p||=1
Normalization: ˉp=p/||p||
P10
Vector Arithematic: Dot Product
A dot product, also called inner product, is:
Geometric Meanings |
---|
p⋅q=pxqx+pyqy+pzqz=pTq=||p||||q||cosθ
- p⋅q=q⋅p
- p⋅(q+r)=p⋅q+p⋅r
- p⋅p=||p||22, a different way to write norm.
- If p·q=0 and p,q≠0 then cosθ=0,then p and q are orthogonal.
P11
Example 2: Particle-Line Projection
✅X为物体中心点的位置,为物体上所有点的整体位移,是前面说的T.
速度是加速度的积分,表示为V或˙X
加速度为F/M,但F比较复杂,与时间、位置、速度都可能有关系。
位置是速度的积分。
P12
Example 3: Plane Representation
S: The signed distance to the plane
Quiz: How to test if a point is within a box?
P13
Example 4: Particle-Sphere Collision
If collision does happen, then:
||p(t)−c||2=r2
(p−c+tv)·(p−c+tv)=r2
(v·v)t2+2(p−c)·vt+(p−c)·(p−c)−r2=0
- Three possiblities:
- No root、无碰撞
- One root、擦边 if t>0
- Two roots:自碰撞 if t>0
P14
Vector Arithematic: Cross Product
The result of a cross product is a vector:
r=p×q=[pyqz−pzqypzqx−pxqzpxqy−pyqx]
- r·p=0;r·q=0;||r||=||p||||q||sinθ
- p×q=−q×p
- p×(q+r)=p×q+p×r
- If p×q=0 and p,q≠0 then sinθ=0, then p and q are parallel (in the same or opposite direction).
P15
Example 5: Triangle Normal and Area
- Cross product gives both the normal and the area.
- The normal depends on the triangle index order, also known as topological order.
P16
Quiz: How to test if three points are on the same line (co-linear)?
P17
Example 6: Triangle Inside/Outside Test
P18
Otherwise, outside.
✅ 假设P点在三角形所在平面上
三个点的顺序很重要,不能搞反。
P19
Example 7: Barycentric Coordinates
Note that:
12(x0−p)×(x1−p)⋅n={12||(x0−p)×(x1−p)||inside12||(x0−p)×(x1−p)||outside
Signed areas:
A2=12(x0−p)×(x1−p)⋅n
A0=12(x1−p)×(x2−p)⋅n
A1=12(x2−p)×(x0−p)⋅n
A0+A1+A2=A
Barycentric weights of p :
b0=A0/Ab1=A1/Ab2=A2/A
b0+b1+b2=1
Barycentric Interpolation
p=b0x0+b1x1+b2x2
✅ 当 p 在三角形外面时,面积为负,但面积总和不变 b0,b1,b2 为 p 在三角形重心坐标系下的坐标
✅ p 在三角形外部、重心坐标同样适用,不过权重有负数。
P20
Gouraud Shading
-
Barycentric weights allows the interior points of a triangle to be interpolated.
-
In a traditional graphics pipeline, pixel colors are calculated at triangle vertices first, and then interpolated within. This is known as Gouraud shading.
-
It is hardware accelerated.
-
It is no longer popular.
✅ 由于硬件能力提升,已经可以做到逐像素。
shading,不再需要此方法
通常也不是逐像素计算重心坐标,而是扫描线算法
例如要计算某一行,可以 :
(1) 插值出行起点像素;
(2) 插值出行终点像素;
(3) 起点与终点间批量插值;
P21
Example 9: Tetrahedral Volume
Edge vectors:
X10=X1−X0X20=X2−X0X30=X3−X0
Base triangle area:
A=12||X10×X20||
Height:
h=x30⋅n=x30⋅x10×x20||x10×x20||
Volume:
\begin{align*} V&=\frac{1}{3} ℎA=\frac{1}{6} \mathbf{x} _{30}\cdot \mathbf{x} _{10}\times \mathbf{x} _{20}\\ &=\frac{1}{6}\begin{vmatrix} \mathbf{x} _1 & \mathbf{x} _2 & \mathbf{x} _3 &\mathbf{x} _0 \\ 1& 1 & 1 &1 \end{vmatrix} \end{align*}
✅ 四面体
h是\mathbf{x}_{30}在 normal 上的投影
行列式是上面叉乘的另一种马法。
P22
Note that the volume V =\frac{1}{3}h\mathit{A} =\frac{1}{6} \mathbf{x} _ {30}\cdot (\mathbf{x} _ {10}\times \mathbf{x}_{20}) is signed.
✅ \mathbf{x}_{3}的后面法线的同方向上,也正四面体,反之为负四面体,四点共面为零体积。
P23
Example 10: Barycentric Weights (cont.)
- p splits the tetrahedron into four sub-tetrahedra:
\begin{matrix} V_0=\mathrm{Vol} (\mathbf{x}_3,\mathbf{x}_2, \mathbf{x}_1, \mathbf{p} )\\ V_1=\mathrm{Vol} (\mathbf{x}_2,\mathbf{x}_3, \mathbf{x}_0, \mathbf{p} )\\ V_2=\mathrm{Vol} (\mathbf{x}_1,\mathbf{x}_0, \mathbf{x}_3, \mathbf{p} )\\ V_3=\mathrm{Vol} (\mathbf{x}_0,\mathbf{x}_1, \mathbf{x}_2, \mathbf{p} ) \end{matrix}
-
p is inside if and only if: V_0,V_1,V_2, V_3 > 0.
-
Barycentric weights:
b_0=V_0/V \quad b_1=V_1/V \quad b_2=V_2/V \quad b_3=V_3/V
b_0+b_1+b_2+b_3=1
\mathbf{p} =b_0\mathbf{x} _0+b_1\mathbf{x} _1+b_2\mathbf{x} _2+b_3\mathbf{x} _3
P24
Example 11: Particle-triangle Intersection
- First, we find t when the particle hits the plane:
(\mathbf{p} (t)−\mathbf{x} _0)\cdot \mathbf{x} _{10}\times \mathbf{x} _{20}=0
(\mathbf{p}-\mathbf{x} _0+t\mathbf{v})\cdot \mathbf{x} _{10}\times \mathbf{x} _{20}=0
t=\frac{(\mathbf{p}−\mathbf{x}_0)\cdot \mathbf{x} _{10}\times \mathbf{x} _{20}}{\mathbf{v}\cdot \mathbf{x} _{10}\times \mathbf{x} _{20}}
- We then check if \mathbf{p}(t) is inside or not.
- See Example 6.
✅ 代入体积公式,体积为0时发生碰撞
本文出自CaterpillarStudyGroup,转载请注明出处。
https://caterpillarstudygroup.github.io/GAMES103_mdbook/