canvas实现DBSCAN聚类算法可视化过程代码
代码语言:html
所属分类:其他
代码描述:canvas实现DBSCAN聚类算法可视化过程代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!doctype html> <html lang="en-us"> <head> <meta charset="utf-8"> </head> <body> <div class="center"> <article> <div class="social"> </div> <h1 class="title">DBSCAN</h1> <div class="content"><div> <p>A visualization of a <a href="http://en.wikipedia.org/wiki/DBSCAN">DBSCAN algorithm</a>.</p> <style> .post { max-width: none; width: 640px; padding: 0; } </style> <header> <nav id="menu"></nav> <div class="clear"></div> </header> <p><canvas id="canvas" ></canvas></p> <script> Math.TAU = Math.PI*2; function $P(x,y){ return new Point(x,y);} function Point(x,y){ this.x = x; this.y = y; } Point.prototype = { toString : function(){ return "<" + this.x.toFixed(2) + ";" + this.y.toFixed(2) + ">"; } }; function $R(left, top, right, bottom){ return new Rect(left, top, right, bottom); } function Rect(left, top, right, bottom){ this.left = left; this.top = top; this.right = right; this.bottom = bottom; } Rect.prototype = { get width(){ return Math.abs(this.right - this.left); }, get height(){ return Math.abs(this.bottom - this.top); }, get dx(){ return this.right - this.left; }, get dy(){ return this.bottom - this.top; }, get topLeft(){ return new Point(this.left, this.top); }, get bottomRight(){ return new Point(this.right, this.bottom); }, intersect : function(rect){ var left = this.left > other.left ? this.left : other.left, top = this.top > other.top ? this.top : other.top, right = this.right < other.right ? this.right : other.right, bottom = this.bottom < other.bottom ? this.bottom : other.bottom; return new Rect(left, top, right, bottom); } }; function sortRange(zero, from, to, delta){ if (from < to) { return {from:from, to:to, delta:Math.abs(delta)}; } else { return {from:to, to:from, delta:Math.abs(delta)}; } } </script> <script > function clone(obj){ if(typeof(obj) != "object") return obj; var result = {}; for(var i in obj) result[i] = clone(obj[i]); return result; } function foreach(obj, f){ if(obj instanceof Array){ for(var i = 0; i < obj.length; i += 1){ .........完整代码请登录后点击上方下载按钮下载查看
网友评论0