-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconvert-array.js
196 lines (178 loc) · 6.94 KB
/
convert-array.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* code to convert array of points with extra -1s to array of array of array of
* 3 point groups so that openscad can actually use our data
*/
var newPoints = points.map(x => {
return x.filter(y => {
if (y !== -1) {
return true
}
return false
})
})
var newestPoints = newPoints.map(x => {
var arrayOfArrays = [];
var i;
for(i = 0; i < x.length/3; i++) {
arrayOfArrays.push(x.slice(3 * i, 3 * i + 3))
}
return arrayOfArrays
})
console.log(newestPoints);
/**
* code to figure out which points are which for the interpolation
* and converting my weird points to a normal array
*/
var i = 0, j = 0, k = 0
for (l = 0; l <= 2; l++) {
// alternate m so that we get all four sides
for(m = 0; m <= 3; m++) {
var positionOne = [(l == 0) ? i : ((l == 1) ? i + m % 2 : i + (m >= 2 ? 1 : 0)), (l == 1) ? j : ((l == 0) ? j + ((m >= 2) ? 1 : 0) : j + m % 2), (l == 2) ? k : ((l == 0) ? k + m % 2 : k + (m >= 2 ? 1 : 0))];
var positionTwo = [positionOne[0] + ((l == 0) ? 1 : 0), positionOne[1] + ((l == 1) ? 1 : 0), positionOne[2] + ((l == 2) ? 1 : 0)];
console.log("start");
console.log(" m", m);
console.log(" l", l);
console.log(" array value", m + l * 4)
console.log(" position one: ", positionOne);
console.log(" position two: ", positionTwo);
}
}
/**
* refiguring out interpolation
*/
const size = 9;
const allPointsValues = [[[-6.5, -6.5, -6.5], [-6.5, -6.5, -6.5], [-6.5, -6.5, -6.5]], [[2.5, 2.5, 2.5], [2.5, 2.5, 2.5], [2.5, 2.5, 2.5]], [[11.5, 11.5, 11.5], [11.5, 11.5, 11.5], [11.5, 11.5, 11.5]]];
const i = 0;
const j = 0;
const k = 0
console.log((() => {
let output = [];
for (var l = 0; l <= 2; l++) {
// alternate m so that we get all four sides
for(var m = 0; m <= 3; m++) {
var positionOne = [(l == 0) ? i : ((l == 1) ? i + m % 2 : i + (m >= 2 ? 1 : 0)), (l == 1) ? j : ((l == 0) ? j + ((m >= 2) ? 1 : 0) : j + m % 2), (l == 2) ? k : ((l == 0) ? k + m % 2 : k + (m >= 2 ? 1 : 0))]
var positionTwo = [positionOne[0] + ((l == 0) ? 1 : 0), positionOne[1] + ((l == 1) ? 1 : 0), positionOne[2] + ((l != 2) ? 1 : 0)]
var valueOne = allPointsValues[positionOne[0]][positionOne[1]][positionOne[2]]
let valueTwo = allPointsValues[positionTwo[0]][positionTwo[1]][positionTwo[2]]
// check if two points have opposite signs because that is when there is a point on the edge
if ((valueOne < 0) ? (valueTwo > 0) : (valueTwo < 0)) {
// this if might never be called
if (valueOne == valueTwo) {
edgePoints[(l * 4 + m)]
} else {
let temp = [];
for(var n = 0; n <= 2; n++) {
// i derived this equation using point slope form
temp.push(valueOne * size / (valueOne - valueTwo))
}
output.push(temp);
}
} else {
// this needs parens, idk why
// edgePoints[(l * 4 + m)]
output.push(0)
}
}
}
return(output);
})());
/**
* more testing with newest stuff to figure out why when one of the points is zero, the algorithm picks the
* the opposite side than it should to put the point
*/
const size = 10;
const allPointsValues = [[[-20, -20, -20], [-10, -10, -10], [0, 0, 0]], [[-10, -10, -10], [0, 0, 0], [10, 10, 10]], [[0, 0, 0], [10, 10, 10], [20, 20, 20]]]
const i = 1;
const j = 0;
const k = 0;
console.log((() => {
let output = [];
for (var l = 0; l <= 2; l++) {
// alternate m so that we get all four sides
for(var m = 0; m <= 3; m++) {
var positionOne = [(l == 0) ? i : ((l == 1) ? i + m % 2 : i + (m >= 2 ? 1 : 0)), (l == 1) ? j : ((l == 0) ? j + ((m >= 2) ? 1 : 0) : j + m % 2), (l == 2) ? k : ((l == 0) ? k + m % 2 : k + (m >= 2 ? 1 : 0))]
var positionTwo = [positionOne[0] + ((l == 0) ? 1 : 0), positionOne[1] + ((l == 1) ? 1 : 0), positionOne[2] + ((l == 2) ? 1 : 0)]
var valueOne = allPointsValues[positionOne[0]][positionOne[1]][positionOne[2]]
let valueTwo = allPointsValues[positionTwo[0]][positionTwo[1]][positionTwo[2]]
console.log(positionOne);
console.log(positionTwo);
// check if two points have opposite signs because that is when there is a point on the edge
if ( valueOne == 0 || valueTwo == 0 || (valueOne < 0) ? (valueTwo > 0) : (valueTwo < 0)) {
// this if might never be called
if (valueOne == valueTwo) {
0
} else {
let temp = [];
for(var n = 0; n <= 2; n++) {
// i derived this equation using point slope form
if (positionTwo[n] - positionOne[n] === 1){
temp.push(valueOne * size / (valueOne - valueTwo))
} else if (positionOne[n] === 1) {
temp.push(size);
} else {
temp.push(0);
}
}
output.push(temp);
}
} else {
// this needs parens, idk why
// edgePoints[(l * 4 + m)]
output.push(0)
}
}
}
return(output);
})());
/**
* try two of up top stuff
*/
const size = 10;
const allPointsValues = [[[-20, -20, -20], [-10, -10, -10], [0, 0, 0]], [[-10, -10, -10], [0, 0, 0], [10, 10, 10]], [[0, 0, 0], [10, 10, 10], [20, 20, 20]]]
const i = 1;
const j = 0;
const k = 0;
console.log((() => {
let output = [];
for (var l = 0; l <= 2; l++) {
// alternate m so that we get all four sides
for(var m = 0; m <= 3; m++) {
var positionOne = [(l == 0) ? i : ((l == 1) ? i + m % 2 : i + (m >= 2 ? 1 : 0)), (l == 1) ? j : ((l == 0) ? j + ((m >= 2) ? 1 : 0) : j + m % 2), (l == 2) ? k : ((l == 0) ? k + m % 2 : k + (m >= 2 ? 1 : 0))]
var positionTwo = [positionOne[0] + ((l == 0) ? 1 : 0), positionOne[1] + ((l == 1) ? 1 : 0), positionOne[2] + ((l == 2) ? 1 : 0)]
var valueOne = allPointsValues[positionOne[0]][positionOne[1]][positionOne[2]]
let valueTwo = allPointsValues[positionTwo[0]][positionTwo[1]][positionTwo[2]]
console.log("positionone")
console.log(" ", positionOne);
console.log("position two")
console.log(" ", positionTwo);
// check if two points have opposite signs because that is when there is a point on the edge
if ( valueOne == 0 || valueTwo == 0 || (valueOne < 0) ? (valueTwo > 0) : (valueTwo < 0)) {
// this if might never be called
if (valueOne == valueTwo) {
0
} else {
let temp = [];
for(var n = 0; n <= 2; n++) {
// i derived this equation using point slope form
if (positionTwo[n] - positionOne[n] === 1) {
temp.push(valueOne * size / (valueOne - valueTwo))
} else if (positionOne[n] === 1) {
temp.push(size);
} else {
temp.push(0);
}
}
output.push(temp);
}
} else {
// this needs parens, idk why
// edgePoints[(l * 4 + m)]
output.push(0)
}
console.log("output");
// console.log(output)
console.log(" ", output[m + 4 * l])
}
}
return(output);
})());