Commit 2cb2f497 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

mill xz yz, vectorization issues?

parent 9c4c1b2d
......@@ -127,14 +127,14 @@ var interface = function(div){
input.id = mod.div.id+'xz'
input.checked = true
div.appendChild(input)
mod.dirx = input
mod.dirxz = input
div.appendChild(document.createTextNode('xz'))
var input = document.createElement('input')
input.type = 'checkbox'
input.id = mod.div.id+'yz'
input.checked = true
div.appendChild(input)
mod.diry = input
mod.diryz = input
div.appendChild(document.createTextNode('yz'))
div.appendChild(document.createElement('br'))
//
......@@ -283,6 +283,8 @@ function calculate_path() {
diameter:mod.dia_mm.value,
stepover:mod.stepover.value,
mmunits: mod.mmunits,
xz:mod.dirxz.checked,
yz:mod.diryz.checked,
map:mod.map})
}
//
......@@ -303,7 +305,7 @@ function calculate_path_worker() {
var diameter = evt.data.diameter
var stepover = evt.data.stepover
var mmunits = evt.data.mmunits
var ystep = Math.floor(stepover*diameter*w/(mmunits*(xmax-xmin)))
var step = Math.floor(stepover*diameter*w/(mmunits*(xmax-xmin)))
var path = [[]]
//
// construct tool offset
......@@ -320,92 +322,184 @@ function calculate_path_worker() {
tooloffset[y*toolsize+x] = Number.MAX_VALUE
}
//
// loop over lines
// xz
//
var xstart = 0
var ystart = h-1
var zstart = Math.floor((map[ystart*w+xstart]-zmax)*w/(xmax-xmin))
path[0].push([xstart,h-1-ystart,zstart])
var xcur = 1
var ycur = h-1
var zcur = Math.floor((map[ycur*w+xcur]-zmax)*w/(xmax-xmin))
var dx = 1
var dy = 0
while (1) {
//
// move to next point
//
xnext = xcur+dx
ynext = ycur+dy
if (ynext <= 0)
if (evt.data.xz) {
var xstart = 0
var ystart = h-1
var zstart = Math.floor((map[ystart*w+xstart]-zmax)*w/(xmax-xmin))
path[0].push([xstart,h-1-ystart,zstart])
var xcur = 1
var ycur = h-1
var zcur = Math.floor((map[ycur*w+xcur]-zmax)*w/(xmax-xmin))
var dx = 1
var dy = 0
while (1) {
//
// done
// move to next point
//
break;
//
// find offset at next point
//
var znext = -Number.MAX_VALUE
for (var xoffset = 0; xoffset < toolsize; ++xoffset)
for (var yoffset = 0; yoffset < toolsize; ++yoffset) {
var x = xnext+(xoffset-toolmiddle)
var y = ynext+(yoffset-toolmiddle)
var offset = tooloffset[yoffset*toolsize+xoffset]
var z = Math.floor((map[y*w+x]-zmax)*w/(xmax-xmin))-offset
if (z > znext)
znext = z
xnext = xcur+dx
ynext = ycur+dy
if (ynext <= 0)
//
// done
//
break;
//
// find offset at next point
//
var znext = -Number.MAX_VALUE
for (var xoffset = 0; xoffset < toolsize; ++xoffset)
for (var yoffset = 0; yoffset < toolsize; ++yoffset) {
var x = xnext+(xoffset-toolmiddle)
var y = ynext+(yoffset-toolmiddle)
var offset = tooloffset[yoffset*toolsize+xoffset]
var z = Math.floor((map[y*w+x]-zmax)*w/(xmax-xmin))-offset
if (z > znext)
znext = z
}
//
// vectorize
//
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-zcur
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 (dot <= (1-error)) {
path[0].push([xcur,h-1-ycur,zcur])
xstart = xcur
ystart = ycur
zstart = zcur
}
//
// vectorize
//
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-zcur
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 (dot <= (1-error)) {
path[0].push([xcur,h-1-ycur,zcur])
xstart = xcur
ystart = ycur
zstart = zcur
}
xcur = xnext
ycur = ynext
zcur = znext
if (xcur == (w-1)) {
if (dx == 1) {
dx = 0
dy = -ystep
xcur = xnext
ycur = ynext
zcur = znext
if (xcur == (w-1)) {
if (dx == 1) {
dx = 0
dy = -step
}
else {
dx = -1
dy = 0
}
}
else {
dx = -1
dy = 0
else if (xcur == 0) {
if (dx == -1) {
dx = 0
dy = -step
}
else {
dx = 1
dy = 0
}
}
//
// update progress
//
self.postMessage({type:'progress',value:ycur})
}
else if (xcur == 0) {
if (dx == -1) {
dx = 0
dy = -ystep
}
//
// yz
//
if (evt.data.yz) {
var xstart = w-1
var ystart = 0
var zstart = Math.floor((map[ystart*w+xstart]-zmax)*w/(xmax-xmin))
path[0].push([xstart,h-1-ystart,zstart])
var xcur = w-1
var ycur = 1
var zcur = Math.floor((map[ycur*w+xcur]-zmax)*w/(xmax-xmin))
var dx = 0
var dy = 1
while (1) {
//
// move to next point
//
xnext = xcur+dx
ynext = ycur+dy
if (xnext <= 0)
//
// done
//
break;
//
// find offset at next point
//
var znext = -Number.MAX_VALUE
for (var xoffset = 0; xoffset < toolsize; ++xoffset)
for (var yoffset = 0; yoffset < toolsize; ++yoffset) {
var x = xnext+(xoffset-toolmiddle)
var y = ynext+(yoffset-toolmiddle)
var offset = tooloffset[yoffset*toolsize+xoffset]
var z = Math.floor((map[y*w+x]-zmax)*w/(xmax-xmin))-offset
if (z > znext)
znext = z
}
//
// vectorize
//
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-zcur
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 (dot <= (1-error)) {
path[0].push([xcur,h-1-ycur,zcur])
xstart = xcur
ystart = ycur
zstart = zcur
}
xcur = xnext
ycur = ynext
zcur = znext
if (ycur == (w-1)) {
if (dy == 1) {
dy = 0
dx = -step
}
else {
dy = -1
dx = 0
}
}
else {
dx = 1
dy = 0
else if (ycur == 0) {
if (dy == -1) {
dy = 0
dx = -step
}
else {
dy = 1
dx = 0
}
}
//
// update progress
//
self.postMessage({type:'progress',value:ycur})
}
//
// update progress
//
self.postMessage({type:'progress',value:ycur})
}
//
// return
......
This diff is collapsed.
Markdown is supported
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