{{ message }}

Instantly share code, notes, and snippets.

# Sebastian Sylvanssylvan

Last active Sep 7, 2018
View gist:80debcac11605f357e5a45d7aa55058d
 // Example: ctx.ClearScreen(); let ctx = ctx.BeginTriangleStrip(); // Old context is *consumed*, new context has different methods // ctx.ClearScreen(); // ERRROR: not supported on this context ctx.AddVertex(...); ctx.AddVertex(...); ctx.AddVertex(...); let ctx = ctx.End();
Last active Jan 17, 2019
Sudoku solver
View main.cpp
 #include #include #include #include #include int get_set_bit(uint16_t x) { assert(__popcnt16(x) == 1); unsigned long index; _BitScanForward(&index, x);
Last active Dec 15, 2017
View gist:d193d2bbb838e9e4a452658af23b71d4
 /* Need cost function to divide by z, so that the errors we minimize are _projected_ errors. Without it, 1px error might be 1mm if the ball is close up, or 100mm if the ball is further away. Thus to minimize error the optimizer would move the ball closer. By optimizing projected error there's no such bias. */ float CostFunction(vec3 dir, float r, vec3 pos) { // Compute distance to the sphere surface vec3 posOnSphere = dir*dot(dir, pos); vec3 dirToRay = posOnSphere - pos;
Last active Mar 14, 2016
Ray-point optimization
View gist:0309be58e5448e3c7989

I would've derived it differnetly. Rather than explicitly setting up the equation for squared distances then finding the solution that minimizes it, I would've just used the normal equations to do the least squares part for me. IMO this makes it a bit more "mechanical" in figuring out the soluion (I just need to figure out what equation I'm trying to solve, the normal equation can be memorized and will figure out how to compute the least squares solution to it).

So we already have the equation from the stackexchange thing for computing the "offset vector" from a point to the line. You can express this in different ways, but they way they did it is fine. Basically the 3D vector telling us how far a point x is from the line described by an origin o and a direction u.

ray_to_point_offset = (I - u*ut)*x - (I-u*ut)*o

That first term is "x projected onto a plane with normal u", and the second term is "ray origin projected to the same plane". So the difference between the two is just finding the perpendicu

Last active Jan 12, 2016
View gist:8b19fb016983a1ae38b7
 const fs = require('fs'); const path = require('path'); const glob = require('glob'); const jsdom = require("jsdom").jsdom; const cwd = path.resolve(process.argv); console.log(cwd); var files = glob.sync("*.html", {cwd: path.resolve(process.argv), matchBase:true, follow: true, realpath:true});
Created Nov 20, 2015