This is an implementation of Welzl (1991) algorithm of smallest enclosing circle. Uses some parts of Mike Bostock's code for circumscribed discs.
Move points around and click to add new ones.
/** | |
* Intersection point of 2 circles | |
* | |
* http://paulbourke.net/geometry/circlesphere/ | |
* | |
* @param {number} x0 | |
* @param {number} y0 | |
* @param {number} r0 | |
* @param {number} x1 | |
* @param {number} y1 |
// Prototype of a utility function to swap two integers | |
const swap = (arr, x, y) => { | |
let tmp = arr[x]; | |
arr[x] = arr[y]; | |
arr[y] = tmp; | |
}; | |
const parent = (index) => Math.floor((index - 1) / 2); | |
/** | |
* Min heap priority queue implementation | |
* | |
* @param {Array} [arr] [[]] | |
* @param {function (a:number, b:number)} [cmp] [function (a, b) { return a - b; }] Comparator | |
* @return {Object} | |
*/ | |
const heap = function (arr, cmp = (a, b) => a - b) { | |
/** |
function minHeap (cmp, arr = []) { | |
const up = (i) => { | |
let object = arr[i]; | |
while (i > 0) { | |
let up = ((i + 1) >> 1) - 1, | |
parent = arr[up]; | |
if (cmp(object, parent) >= 0) break; | |
arr[parent.index = i] = parent; | |
arr[object.index = i = up] = object; |
This is an implementation of Welzl (1991) algorithm of smallest enclosing circle. Uses some parts of Mike Bostock's code for circumscribed discs.
Move points around and click to add new ones.
license: gpl-3.0 | |
height: 960 |
license: gpl-3.0 | |
height: 960 |
class Matrix { | |
constructor (h, w, ArrayType = Uint32Array) { | |
this._w = w; | |
this._h = h; | |
this._arrayType = ArrayType; | |
this._mtr = new (this._arrayType)(this._w * this._h); | |
} | |
get (r, c) { | |
return this._mtr[this._w * r + c]; |
<!doctype html> | |
<html> | |
<head> | |
<title>Measure rtree for feature detection</title> | |
<script src="https://unpkg.com/d3@4.4.1"></script> | |
<script src="https://unpkg.com/rbush@2.0.1/rbush.min.js"></script> | |
<style> | |
html, body { | |
width: 100%; |
function sqrt(x, eps = 1e-3){ | |
function mean(a,b){ | |
return (a + b) / 2 | |
} | |
function newEstimate(estimate){ | |
return mean( estimate, x / estimate ) | |
} |