Sort 5 Elements in 7 Steps

*A smart and interesting sorting. Suppose I have five elements: a, b, c, d, e. And I want to sort them in 7 steps: Step 1: 3 comparisons: if a > b: swap(a, b); if c > d: swap(c, d); if b > d: swap(b, d), swap(a, c) ![Imgur](https://i.imgur.com/qzLVYmQ.png =200x200) Step 2: 2 comparisons: now I need to find the position for e in {a, b, d}: if (e < b) if (e < a) e a b d else a e b d else if (e < d) a b e d else a b d e !...

October 25, 2018 · Kyle Fang

Three.js - shaderMaterial and vertex/fragment shaders

A vertex shader: //WebGL Vertex Shader uniform mat4 uMVMatrix; // Model-view matrix uniform mat4 uPMatrix; // Projection matrix uniform mat4 uNMatrix; // Normal matrix attribute vec3 aVertexPosition; // Vertex position in object space attribute vec3 aVertexNormal; // Vertex normal in object space varying vec3 vPosition; // Vertex position (camera space) varying vec3 vNormal; // Vertex normal (camera space) void main(void) { vec4 camSpacePosition = uMVMatrix * vec4(aVertexPosition, 1....

June 13, 2018 · Kyle Fang

Derivative

The First Derivative The first derivative is the slop of the tangent line to the function at point x. It tells if the function is increasing or decreasing. For example: $f(x) = 3x^3 - 6x^2 + 2x -1$ $\frac{df}{dx} = 9x^2 - 12x + 2$ $x=0$, $\frac{df}{dx}(0) = 2$, so the function is increasing at x = 0. $x = 1$, $\frac{df}{dx}(1) = 9 - 12 + 2 = -1$, so the function is decreasing at x = 1....

May 17, 2018 · Kyle Fang

Sphere Coordinates and Trigonometry

Sphere in 3-D three parameters: (r, θ, φ) $x = r \cdot sin(φ) cos(θ)$ $y = r \cdot sin(φ) sin(θ)$ $z = r \cdot cos(θ)$ Trigonometry $\cos(θ) = \frac{x}{\sqrt{x^{2} + y^{2}}}$ $\sin(θ) = \frac{y}{\sqrt{x^{2} + y^{2}}}$ $\tan(θ) = \frac{y}{x}$ arcsin/arccos/arctan is the inverse. e.g. $\tan(45^{\circ}) = 1$ $\arctan(1) = 45^{\circ}$

May 13, 2018 · Kyle Fang

Verb Tense in English

Each sentence takes a place in a specific moment, and aspects tell us the status of the action at that moment Past Continuous/Progressive “We were sleeping when the sea creature attacked.” Perfect “We had departed from Nantucket.” Perfect Progressive “We had been sailing three weeks.” Simple “We went to search a sea creature.” “Sea creature attacked us.” Present Continuous/Progressive “We’re preparing for their next mission.” Perfect “We have built a special submarine for the search mission....

May 2, 2018 · Kyle Fang