Skip to content

Instantly share code, notes, and snippets.

View fospathi's full-sized avatar

Christian Stewart fospathi

View GitHub Profile
/// Print the calculation which multiplies two 3x3 matrices.
///
/// The matrices store their elements in a flat array in column order.
void main() {
StringBuffer buffer = new StringBuffer();
String l = "m1";
String r = "m2";
for (int col in new Iterable.generate(3)) {
for (int row in new Iterable.generate(3)) {
buffer.writeAll([
/// Print the calculation which multiplies two 4x4 matrices.
///
/// The matrices store their elements in a flat array in column order.
void main() {
StringBuffer buffer = new StringBuffer();
String l = "m1";
String r = "m2";
for (int col in new Iterable.generate(4)) {
for (int row in new Iterable.generate(4)) {
buffer.writeAll([
/// Print the calculation which multiplies two 3x4 affine transformation
/// matrices.
///
/// The matrices store their elements in a flat array in column order.
void main() {
StringBuffer buffer = new StringBuffer();
String l = "a1";
String r = "a2";
for (int col in new Iterable.generate(4)) {
for (int row in new Iterable.generate(3)) {
@fospathi
fospathi / reflect_horizontally.txt
Last active April 12, 2018 23:52
The reflection of f(x) in the vertical line x=k is given by f(2k-x)
Produce a new function which is a horizontal reflection of the function f{x} in the vertical line x=k.
There are three steps: (1) horizontally translate the function in such a way that the reflection can be applied across the
Y-axis (i.e. all points on the translated function's curve should be the same distance from the Y-axis as they originally
were from the line x=k); (2) perform a reflection across the Y-axis; (3) reverse the translation made in step 1.
1. Consider the translation necessary to make the line x=k coincide with the Y-axis. Apply this translation to f{x}
producing f₁{x}.
f₁{x} = f{x+k}
@fospathi
fospathi / quadratic_bezier_plane_intersections.txt
Last active June 10, 2024 15:03
Intersection points of a quadratic Bezier curve and a plane
Find the values of the parameter t (in the range 0..1 inclusive) at the intersection points of a quadratic Bezier curve
and a plane in three dimensions.
Let P₀, P₁, and P₂ be the control points of a quadratic Bezier curve B such that
B{t} = (1-t)²P₀ + 2(1-t)(t)P₁ + (t²)P₂
Let A be a unit normal vector to the plane where Q is any position vector on the plane such that
A⋅Q = d
@fospathi
fospathi / useful_chars.txt
Last active December 7, 2020 01:36
Useful technical characters not found on a keyboard
₀₁₂₃₄₅₆₇₈₉ ⁰¹²³⁴⁵⁶⁷⁸⁹ ⁺⁻⁼⁽⁾ ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴿᵀᵁⱽᵂ
⋅±→∠⨯ √ ‥
αβγδεζηθικλμνξοπρςστυφχψω
Α α, Β β, Γ γ, Δ δ, Ε ε, Ζ ζ, Η η, Θ θ, Ι ι, Κ κ, Λ λ, Μ μ, Ν ν, Ξ ξ, Ο ο, Π π, Ρ ρ, Σ σ/ς, Τ τ, Υ υ, Φ φ, Χ χ, Ψ ψ, Ω
ᵦ ᵧ ᵨ ᵩ ᵪ ᵅ ᵝ ᵞ ᵟ ᵋ ᶿ ᶥ ᶲ ᵠ ᵡ
@fospathi
fospathi / change_basis.txt
Last active March 3, 2020 03:06
Change of basis transformation
Consider a standard coordinate system C in three dimensions. Let a linear transformation R be any rotation or reflection
around or through the origin respectively.
Let R be applied to the orthonormal basis vectors that define the axis directions of C. Let R be applied to any points
in C, say P₀ and P₁.
R: C → C'
R: P₀, P₁ → P'₀, P'₁
A new coordinate system C' results whose axis directions are the transformed axis directions of C under the
@fospathi
fospathi / svg_matrix_y_flip.txt
Last active August 15, 2022 23:20
SVG matrix to flip the Y-axis direction
The Y-axis in an SVG document points towards the bottom of the page, that is the Y value increases the further down the page
you go. When positioning items in a maths or physics context however it is more appropriate to have the Y-axis pointing up
the page like a normal coordinate system. We can provide an affine transformation matrix to a g element's transform
attribute that flips the Y-axis for its children.
Let the value of the viewBox attribute of the document's SVG element equal "0 0 w h". Suppose we want a coordinate system
whose origin is at the centre of the viewbox and whose Y-axis points up to the top of the page.
(0, 0)
O_ _ _ _ _ _ _ _\ X (Default SVG coordinate system/frame)
@fospathi
fospathi / closest_approach_lines.txt
Last active April 17, 2018 15:47
Closest approach of two lines
Let L₀ = P₀ + αD₀ and L₁ = P₁ + βD₁ be two lines. Let P = P₁ - P₀ and
L = L₁ - L₀
= P - αD₀ + βD₁
Then
L² = L⋅L
= (P - αD₀ + βD₁)⋅(P - αD₀ + βD₁)
= P² + (αD₀)² + (βD₁)² - 2α(P⋅D₀) + 2β(P⋅D₁) - 2αβ(D₀⋅D₁)
@fospathi
fospathi / 3d_rotation_matrices.txt
Last active March 28, 2019 11:20
3D rotation matrices
Affine transformation matrices to rotate around (1) the X-axis; (2) the Y-axis; (3) the Z-axis; (4) an arbitrary 3D line. A
right-handed coordinate system is assumed.
1. X-axis
Z-axis | 'B A and B are two points in a YZ-plane
| ' ∠ AOB = β
| ' `A ∠ YOA = α
| ' ` |OA| = |OB| = r
| ' `