Skip to content

Instantly share code, notes, and snippets.

View ievgennaida's full-sized avatar

Ievgen Naida ievgennaida

View GitHub Profile
@BriSeven
BriSeven / decompose-matrix.js
Last active May 23, 2021 15:21
Decompose a 2D transform matrix into [rotate scale rotate translate]
function decomposeMatrix(m) {
var t,r,s,k,E,F,G,H,Q,R,sx,sy,a1,a2,theta,phi,sqrt=Math.sqrt,atan2=Math.atan2;
// http://math.stackexchange.com/questions/861674/decompose-a-2d-arbitrary-transform-into-only-scaling-and-rotation
//
// It works wonderfully! Thanks.
// The input matrix is transposed though,
// so let me spell the solution out.
E=(m[0]+m[3])/2
@tunght13488
tunght13488 / quadratic-bezier.js
Last active December 15, 2023 10:13
quadratic bezier curve length in javascript
/*
* http://en.wikipedia.org/wiki/B%C3%A9zier_curve
* http://www.malczak.linuxpl.com/blog/quadratic-bezier-curve-length/g
*/
function Point(x, y) {
this.x = x;
this.y = y;
}
@skeggse
skeggse / consumer.js
Created October 3, 2013 00:44
A Node.js backpressure example over a tcp/net stream. Just run index.js, the output is a little shoddy but it works. The producer only produces once the consumer catches up, but the streams are disconnected--they can't communicate directly.
var net = require('net');
var util = require('util');
var Writable = require('stream').Writable;
/**
* Pretends to consume the data written to it. In reality, it just eats data
* really slowly.
*
* @constructor
* @extends Writable
@fwextensions
fwextensions / gist:2052247
Created March 16, 2012 19:58
Decomposing a 2D transformation matrix to find the skew
/*
This code takes a 2D transformation matrix described as a one-dimensional array
(in column order, top to bottom and left to right) and decomposes it using the dojo
matrix library. This input matrix should produce a 45-deg X skew:
1 1 0
0 1 0
0 0 1
The output of decompose() looks like this: