JavaScript “loose” comparison, step by step

This handy tool visualizes loose comparison (==) in JavaScript works:

Below you can provide two values to compare, and see which steps of the “Abstract Equality Algorithm” as defined in Section 7.2.14 of the ECMAScript specification are executed.

JavaScript “loose” comparison, step by step →

When Algorithms Design a Concert Hall

The auditorium of Hamburg’s newly opened concert hall, the Elbphilharmonie, looks amazing.

The auditorium is a product of parametric design, a process by which designers use algorithms to develop an object’s form. In the case of the Elbphilharmonie, Herzog and De Meuron used algorithms to generate a unique shape for each of the 10,000 gypsum fiber acoustic panels that line the auditorium’s walls like the interlocking pieces of a giant, undulating puzzle.

What Happens When Algorithms Design a Concert Hall →

Extracting Looping GIFs From Videos

3y3OI1b

Finding and extracting well-looping segments from a movie requires much attention and patience […] To make things easier I wrote a Python script which automates the task. This post explains the math behind the algorithm and provides a few examples of use.

Fuck yeah, math! Or, as the author states:

Yet another big problem of the Internet era tackled by Mathematics.

An Algorithm to Extract Looping GIFs From Videos →

(via @patrickdebois)

Apple, Apps and Algorithmic Glitches

1-196TOMMTbm-TsXCwsA45Cw

On October 29th and December 18th, 2014, something very strange happened to the iTunes top apps chart. Like an earthquake shaking up the region, all app positions in the chart were massively rearranged, some booted off completely. These two extremely volatile days displayed rank changes that are orders of magnitude higher than the norm — lots of apps moving around, lots of uncertainly.

Highly interesting analysis and conclusion.

Apple, Apps and Algorithmic Glitches: A data analysis of iTunes’ top chart algorithm →

PathFinding.js – A comprehensive path-finding library for grid based games

pathfindingjs

The aim of this project is to provide a path-finding library that can be easily incorporated into web games. It may run on Node.js or the browser.

PathFinding.js Demo →
PathFinding.js source →

Convert LAMBERT 1972 to WGS84

Needed to convert LAMBERT 1972 (EPSG:31370) coordinates to WGS84 (EPSG:4326) for a project I’m working on in order to use the coordinates with Google Maps (which uses a SphericalMercator (EPSG:900913) projection).

Took me quite a while to find the needed algorithm, so hereby I’m listing them (and am providing the JavaScript implementation):

JavaScript:

var lambert72toWGS84 = function(x, y){

	var newLongitude, newLatitude;

	var n = 0.77164219,
	    F = 1.81329763,
		thetaFudge = 0.00014204,
		e = 0.08199189,
		a = 6378388,
		xDiff = 149910,
		yDiff = 5400150,
		theta0 = 0.07604294;

	var xReal = xDiff - x,
	    yReal = yDiff - y;

	var rho = Math.sqrt(xReal * xReal + yReal * yReal),
	    theta = Math.atan(xReal / -yReal);

	newLongitude = (theta0 + (theta + thetaFudge) / n) * 180 / Math.PI;
	newLatitude = 0;

	for (var i = 0; i < 5 ; ++i) {
		newLatitude = (2 * Math.atan(Math.pow(F * a / rho, 1 / n) * Math.pow((1 + e * Math.sin(newLatitude)) / (1 - e * Math.sin(newLatitude)), e / 2))) - Math.PI / 2;
	}
	newLatitude *= 180 / Math.PI;
	return [newLatitude, newLongitude];

}

Java:

public static Point lambert72toWGS84(double x, double y) {

	double newLongitude;
	double newLatitude;

	double n = 0.77164219;
	double F = 1.81329763;
	double thetaFudge = 0.00014204;
	double e = 0.08199189;
	double a = 6378388;
	double xDiff = 149910;
	double yDiff = 5400150;

	double theta0 = 0.07604294;

	double xReal = xDiff - x;
	double yReal = yDiff - y;

	double rho = Math.sqrt(xReal * xReal + yReal * yReal);
	double theta = Math.atan(xReal / -yReal);

	newLongitude = (theta0 + (theta + thetaFudge) / n) * 180 / Math.PI;
	newLatitude = 0;

	for (int i = 0; i < 5 ; ++i) {
		newLatitude = (2 * Math.atan(Math.pow(F * a / rho, 1 / n) * Math.pow((1 + e * Math.sin(newLatitude)) / (1 - e * Math.sin(newLatitude)), e / 2))) - Math.PI / 2;
	}
	newLatitude *= 180 / Math.PI;
	return new Point(newLatitude, newLongitude);
}

C/C++:

void LambertToLongLat(double x,double y, double& longt, double& lat){
    double n = 0.77164219;
    double F = 1.81329763;
    double thetaFudge = 0.00014204;
    double e= 0.08199189;
    double a= 6378388;
    double xDiff= 150000;
    double yDiff = 5400088.44;
    double theta0 = 0.07604294;

    double xReal = xDiff-x;
    double yReal = yDiff-y;

    double rho = sqrt(xReal*xReal + yReal * yReal);
    double theta = atan(xReal/-yReal);

    longt = (theta0 + (theta+thetaFudge) /n)*180/PI;
    lat =0;
    for(size_t i=0; i<5; ++i){
        lat =(2*atan(pow(F*a/rho,1/n)* pow((1+ e*sin(lat))/(1-e*sin(lat)),e/2)))-PI/2;
    }
    lat *=180/PI;
}

Hope this helps!

Related: if you want to do other transforms (or flip the transorm), check out Transformation between datum’s in JavaScript. Thanks for the tip, Ibrahim (via e-mail)!

Did this help you out? Like what you see?
Consider donating.

I don't run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

☕️ Buy me a Coffee ($3)

Pinterest’s div stacking layout algorithm

The number of columns adjusts to fit more/less on browser resize and the vertical stacking is not dependent on adjacent column heights. The source code shows that each div is positioned absolute. I would love to know how to accomplish this.

What technology is used to generate pinterest.com’s absolute div stacking layout? →

Paper: Selecting good still frames from a video

In this paper, we train a computer to select still frames from video that work well as candid portraits. Because of the subjective nature of this task, we conduct a human subjects study to collect ratings of video frames across multiple videos. Then, we compute a number of features and train a model to predict the average rating of a video frame.

Pretty neat results!

Download the paper →
Candid Portrait Selection From Video →