Skip to content

Instantly share code, notes, and snippets.

View fospathi's full-sized avatar

Christian Stewart fospathi

View GitHub Profile
@fospathi
fospathi / ndc_aspect_distortion.md
Last active March 14, 2023 15:21
Aspect distortion of relative vectors composed in NDC space

Aspect distortion of relative vectors composed in NDC space

The distortion affects relative vectors calculated in NDC (OpenGL Normalised Device Coordinates) space at the point at which they are mapped to a rectangular (i.e. non-square) screen.

Let the metric used to measure distance be the proportion of the height of the (NDC cube)/screen. Let's say we wish to calculate a position Q in NDC which is a desired distance from P on the screen.

@fospathi
fospathi / add_repo_gitlab.md
Last active April 23, 2020 20:27
How to create a new GitLab project from an existing local repository

Create a new GitLab project from an existing local repository

This SSH method assumes your SSH keys are already set up on Gitlab and your local system. The SSH method is preferable as it doesn't require a username and password like the HTTPS method.

In the commands below replace fospathi and nonexistent-project with your username and project name respectively. Execute these commands in the project's top-level directory which usually contains the project's .git directory and other language specific things like a go.mod file for Go modules.

Git push using SSH

Directly push the repo to GitLab to create the new project (some times this step takes multiple attempts before success):

@fospathi
fospathi / identical_errors_go.md
Last active April 7, 2023 00:43
Why are Go's identical errors not equal?

⚠️ This discussion applies to version 1.13 (released 2019) of the Go language.

Why are Go's identical errors not equal?

Or, more precisely, why are two separate but otherwise seemingly identical errors created by Go's errors.New function not equal according to the == operator?

Consider the output of the following small program (Go Playground link) which compares Go's error values for equality:

package main
@fospathi
fospathi / aimed_projectile_launch_angle.txt
Created July 31, 2018 10:24
Aimed projectile launch angle
An expression for the launch angle of a parabolic projectile which coincides with a target position vector (x, y) at some
point in its trajectory.
The parametric coordinates of a parabolic projectile launched from the origin are
x = uct
y = ust + at² / 2
where
@fospathi
fospathi / sin_unit_normal.txt
Last active September 27, 2020 16:30
Principal unit normal vector for a sin curve
An expression for the sin curve's principal unit normal vector.
The principal unit normal vector is different from a unit normal vector in that it always points from a point on the curve
towards the centre of the circle that most closely approximates the curvature of the curve at that point. Thus, the principal
unit normal vector is undefined at inflection points since the radius of the circle is infinite at these points.
Consider the parametric form of a sin curve. Let R be a general position vector on a sin curve and let
c = cos(t)
s = sin(t)
@fospathi
fospathi / vector_time_derivatives.txt
Created June 21, 2018 01:20
Examples of time derivatives of vector expressions
Let the vector v be a function of time and k be a constant vector. Find the time derivatives of
1. |v|^2
d |v|^2 = d (v⋅v)
dt dt
= dv⋅v + v⋅dv
dt dt
= 2v⋅dv
dt
@fospathi
fospathi / 3d_reflection_matrix.txt
Last active April 29, 2018 02:18
3D reflection matrix
Affine transformation matrices to reflect a point in (1) the XY-plane through the origin; (2) an arbitrary 3D plane.
A right-handed coordinate system is assumed.
1. XY plane at z=0
Consider a reflection in an XY-plane located at the origin. To accomplish this we require a matrix M such that
|x| | x|
M |y| = | y|
|z| |-z|
@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
| ' `
@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 / 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)