Commit d124f0e7 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

working on z vectorization

parent 237096a8
......@@ -131,14 +131,11 @@ var interface = function(div){
//
// fit error
//
div.appendChild(document.createTextNode('vector fit (%): '))
div.appendChild(document.createTextNode('vector fit: '))
//div.appendChild(document.createElement('br'))
var input = document.createElement('input')
input.type = 'text'
input.size = 6
input.addEventListener('change',function(){
vectorize()
})
div.appendChild(input)
mod.error = input
div.appendChild(document.createElement('br'))
......@@ -255,7 +252,7 @@ function calculate_path() {
}
})
webworker.postMessage({
h:mod.height,w:mod.width,
h:mod.height,w:mod.width,error:mod.error.value,
xmin:mod.xmin,xmax:mod.xmax,
ymin:mod.ymin,ymax:mod.ymax,
zmin:mod.zmin,zmax:mod.zmax,
......@@ -268,6 +265,7 @@ function calculate_path_worker() {
self.addEventListener('message',function(evt) {
var h = evt.data.h
var w = evt.data.w
var error = evt.data.error
var xmin = evt.data.xmin
var xmax = evt.data.xmax
var ymin = evt.data.ymin
......@@ -279,21 +277,46 @@ function calculate_path_worker() {
//
// line loop
//
var ix = 0
var iy = h-1
var dx = 1
var dy = 0
var iz = Math.floor((map[iy*w+ix]-zmax)*w/(xmax-xmin))
xstart = 0
ystart = h-1
zstart = Math.floor((map[ystart*w+xstart]-zmax)*w/(xmax-xmin))
path[0].push([xstart,ystart,zstart])
xcur = 1
ycur = h-1
zcur = Math.floor((map[ycur*w+xcur]-zmax)*w/(xmax-xmin))
dx = 1
dy = 0
while (1) {
var ixp = ix
var iyp = iy
ix += dx
iy += dy
if (iy <= 0)
xnext = xcur+dx
ynext = ycur+dy
znext = Math.floor((map[ynext*w+xnext]-zmax)*w/(xmax-xmin))
if (ynext <= 0)
break;
var iz = Math.floor((map[iy*w+ix]-zmax)*w/(xmax-xmin))
path[0].push([ix,iy,iz])
if (ix == (w-1)) {
dxcur = xcur-xstart
dycur = ycur-ystart
dzcur = zcur-zstart
dcur = Math.sqrt(dxcur*dxcur+dycur*dycur+dzcur*dzcur)
nxcur = dxcur/dcur
nycur = dycur/dcur
nzcur = dzcur/dcur
dxnext = xnext-xcur
dynext = ynext-ycur
dznext = znext-xcur
dnext = Math.sqrt(dxnext*dxnext+dynext*dynext+dznext*dznext)
nxnext = dxnext/dnext
nynext = dynext/dnext
nznext = dznext/dnext
dot = nxcur*nxnext+nycur*nynext+nzcur*nznext
if (Math.abs(dot) >= error) {
path[0].push([xcur,ycur,zcur])
xstart = xcur
ystart = ycur
zstart = zcur
}
xcur = xnext
ycur = ynext
zcur = znext
if (xcur == (w-1)) {
if (dx == 1) {
dx = 0
dy = -10
......@@ -303,7 +326,7 @@ function calculate_path_worker() {
dy = 0
}
}
else if (ix == 0) {
else if (xcur == 0) {
if (dx == -1) {
dx = 0
dy = -10
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment