Skip to content

Instantly share code, notes, and snippets.

@rikusalminen
rikusalminen / pymesh.py
Created January 19, 2018 08:05
Triangle meshes with Python and pygame
import pygame
import pygame.freetype
import pygame.gfxdraw
quadrants = (
(( 0, 0), (+1, -1), (+1, +1)),
(( 0, 0), (+1, +1), (-1, +1)),
(( 0, 0), (-1, +1), (-1, -1)),
(( 0, 0), (-1, -1), (+1, -1)))
@rikusalminen
rikusalminen / gist:972e3824350193bbed0c28ff96a82a73
Created September 10, 2016 16:24
Linux force feedback hello world
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <linux/input.h>
@rikusalminen
rikusalminen / hsv2rgb.c
Created September 13, 2015 09:36
HSV to RGB
#include <math.h>
void hsv2rgb(float h, float s, float v, float *rgb) {
float c = v * s;
float hh = h * 6.0;
float x = c * (1.0 - fabsf(fmodf(hh, 2) - 1.));
float m = v - c;
int i = (int)hh % 6;
rgb[(1 + 2*i)%3] = x + m;
@rikusalminen
rikusalminen / wirecube.vert
Created August 26, 2015 15:23
Wireframe cube in GLSL (usage: glDrawArrays(0, 24))
#version 420
uniform mat4 projection_matrix;
uniform mat4 model_matrix;
void main() {
vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);
int axis = gl_VertexID >> 3;
pos[(axis+0)%3] = (gl_VertexID & 1) >> 0;
pos[(axis+1)%3] = (gl_VertexID & 2) >> 1;
@rikusalminen
rikusalminen / frontpage.tex
Last active April 21, 2022 19:43
Celestial mechanics cheat sheet
% vim:nolist lbr tw=78 expandtab
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape,top=1cm,bottom=1cm,left=1cm,right=1cm]{geometry}
\usepackage[tiny]{titlesec} % smaller titles
\usepackage{multicol}
\usepackage{amsmath}
\pagestyle{empty}
@rikusalminen
rikusalminen / ellipse.tex
Last active March 1, 2017 09:25
Elliptic anomaly in TikZ
% vim:nolist lbr tw=78 expandtab autoindent nocindent
\documentclass[a4paper]{minimal}
\usepackage[landscape,top=1cm,bottom=1cm,left=1cm,right=1cm]{geometry}
\usepackage{tikz}
%\usetikzlibrary{decorations.pathreplacing}
\everymath{\displaystyle} % set math in display style, not text style (ie. larger)
\begin{document}
@rikusalminen
rikusalminen / celestialcheatsheet.tex
Last active August 29, 2015 14:10
Celestial mechanics cheat sheet
% vim:nolist lbr tw=78 expandtab autoindent nocindent
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape,top=1cm,bottom=1cm,left=1cm,right=1cm]{geometry}
%\usepackage{amsmath}
\pagestyle{empty}
\setcounter{secnumdepth}{0}
@rikusalminen
rikusalminen / orbits.gnuplot
Created October 1, 2014 20:48
Plotting satellite orbits with Gnuplot
r(p,e,f) = p/(1.0 + e * cos(f))
orbit_x(p,e,i,an,argp,f) = \
r(p,e,f) * (\
cos(f) * ((cos(argp) * cos(an)) - (sin(argp) * sin(an) * cos(i))) + \
sin(f) * (-(cos(argp) * sin(an) * cos(i)) - (sin(argp) * cos(an))))
orbit_y(p,e,i,an,argp,f) = \
r(p,e,f) * (\
cos(f) * ((sin(argp) * cos(an) * cos(i)) + (cos(argp) * sin(an))) + \
sin(f) * ((cos(argp) * cos(an) * cos(i)) - (sin(argp) * sin(an))))
@rikusalminen
rikusalminen / pyrocket.py
Created July 31, 2014 09:28
Solving the rocket equation in Python
def numerical():
from scipy.integrate import odeint
from numpy import array
# [position, mass, velocity, mass flow]
def acceleration(y, t, v_exhaust=1.0):
return array([y[2], y[3], v_exhaust * y[3]/y[1], 0.0])
initial_state = array([0.0, 2.0, 0.0, -1.0])
@rikusalminen
rikusalminen / universal_var.c
Created June 30, 2014 15:35
Universal variable solution to the Kepler problem
#include <stdbool.h>
#include <float.h>
#include <math.h>
double dot(const double *a, const double *b) {
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
}
double mag(const double *a) {
return sqrt(dot(a, a));