-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolar-scanner-x3d.js
81 lines (62 loc) · 1.94 KB
/
polar-scanner-x3d.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2017, Luc Yriarte
* License: BSD <http://www.opensource.org/licenses/bsd-license.php>
*/
var platformAbstract = {
};
if (typeof exports === "undefined") {
platformAbstract.exports = {};
}
else {
platformAbstract.exports = exports;
}
var PolarScanner = function() {
this._stepper_steps = 512;
this._servo_range = 180;
this._us_precision = 0;
return this;
}
PolarScanner.prototype.indexedFaceSet = function(stpInc, stpNbr, srvInc, srvNbr, srvFrm, scan) {
var ifs =
{
coordIndex: "",
Coordinate:
{
point: ""
}
};
var coords = [];
var stpAngle = 0;
var srvAngle = 0;
for (var i=0; i<scan.length; i++) {
srvAngle = srvFrm + srvInc * (i % srvNbr);
stpAngle += i != 0 && i % srvNbr == 0 ? stpInc : 0;
coords.push((scan[i] * Math.sin(srvAngle) * Math.cos(stpAngle)).toFixed(this._us_precision)); // x
coords.push((scan[i] * Math.cos(srvAngle)).toFixed(this._us_precision)); // y
coords.push((scan[i] * Math.sin(srvAngle) * Math.sin(stpAngle)).toFixed(this._us_precision)); // z
}
var indexes = [];
for (var i=0; i<stpNbr-1; i++) {
for (var j=0; j<srvNbr-1; j++) {
indexes.push(i * srvNbr + j);
indexes.push(i * srvNbr + j+1);
indexes.push((i+1) * srvNbr + j+1);
indexes.push((i+1) * srvNbr + j);
indexes.push(-1);
}
}
indexes.map(function(x) {ifs.coordIndex += x + " "});
coords.map(function(x) {ifs.Coordinate.point += x + " "});
return ifs;
}
PolarScanner.prototype.x3dScan = function(stepper_step, stepper_nbr, servo_step, servo_nbr, servo_from, scan) {
var ifs = this.indexedFaceSet(
stepper_step * 2 * Math.PI / this._stepper_steps, stepper_nbr,
servo_step * Math.PI / this._servo_range, servo_nbr, servo_from * Math.PI / this._servo_range,
scan
);
return '<IndexedFaceSet coordIndex="' + ifs.coordIndex + '">' + "\n"
+ "\t" + '<Coordinate point="' + ifs.Coordinate.point + '"/>' + "\n"
+ '</IndexedFaceSet>' + "\n";
}
platformAbstract.exports.PolarScanner = PolarScanner;