Skip to content

Instantly share code, notes, and snippets.

View fospathi's full-sized avatar

Christian Stewart fospathi

View GitHub Profile
@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 / 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 / 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 / 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 / identical_errors_go.md
Last active May 5, 2024 16:15
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 / 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 / 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.