-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataFoldDuplicate.m
506 lines (338 loc) · 17.5 KB
/
DataFoldDuplicate.m
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
% Duplicating Crease Pattern
% Last Edited 6/22/2021 by Lucien Peach
function [msum, lmax_sum, infostruct, Struct1, Struct2] = ...
DataFoldDuplicate(a, Struct1, Struct2, infostruct, index, msum, lmax_sum, triple)
% infostruct is a data structure that includes all the information needed
% for the construction of the full schematic
% index allows us to know what section of the template we are on. Must be
% an odd number
% msum is a cumulative counter used for resetting along the x axis that
% carries over for each set of appended structures
% First, check to ensure that fold type is not "twist"
if strcmp(infostruct(index).name, "Twist") == 1
name = 1;
else
name = 0;
end
% num will be used to prevent double lines for twists that become tubes
if mod(abs(infostruct(index).m), infostruct(index).ls) < 10^-4 || ...
mod(abs(infostruct(index).m), infostruct(index).ls) > infostruct(index).ls - 10^-4
num = 5;
else
num = 4;
end
% Check will differ based on if index is final in array
if index == size(infostruct, 2)
% Last index check
if infostruct(index).n == infostruct(index-1).n ...
&& infostruct(index).ls == infostruct(index-1).ls
alert = 0;
else
alert = msgbox('Section Width and Number of Vertices Must be Identical', ...
'Error', 'error');
end
else % Any other index check
if infostruct(index).n == infostruct(index+1).n ...
&& infostruct(index).ls == infostruct(index+1).ls
% Do nothing - continue with code
alert = 0;
else
alert = msgbox('Section Width and Number of Vertices Must be Identical', ...
'Error', 'error');
end
end
% A few notes: in order for the above condition to hold, the values of n
% and r must match for all tube components. Thus indexing of r does not
% matter, as long as it can stay consistent throughout loops. Same with n.
% However indexing for m and lmax does matter.
if alert == 0 && strcmp(triple, 'triple') == 0
% Include special case for the first block
if index == 1
% No mod term needed
% Do not consider the m offset here, since it will always be 0.
% Be sure to factor in offset from initial frame.
% If appended to right (no twist)
if infostruct(index).n * infostruct(index).ls <= 2*pi*infostruct(index).r ...
&& name == 0
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
% Ignore left tube line
for i = 6:size(Struct1, 2)
Struct1(i).x = Struct1(i).x + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% If appended to left (no twist)
elseif infostruct(index).n * infostruct(index).ls > 2*pi*infostruct(index).r ...
&& name == 0
% Override right tube data with left tube data, then adjust
% according to specified offset
Struct1(6).x = Struct1(5).x;
Struct1(6).y = Struct1(5).y;
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
for i = 6:size(Struct1, 2)
Struct1(i).x = Struct1(i).x - (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% If appended to right (twist)
elseif infostruct(index).n * infostruct(index).ls <= 2*pi*infostruct(index).r ...
&& name == 1
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
for i = num+1:size(Struct1, 2)
Struct1(i).x = Struct1(i).x + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% If appended to left (twist)
else
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
for i = num+1:size(Struct1, 2)
Struct1(i).x = Struct1(i).x - (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
end
% End of index = 1.
else % If index is not equal to 1
% Mod term
if mod(msum + infostruct(index-1).m, 2*pi*infostruct(index).r) ...
< infostruct(index-1).m + msum && mod(msum + infostruct(index-1).m, ...
2*pi*infostruct(index).r) ~= 0
% If the beginning of this structure is over the 2*pi*r limit,
% adjust so that it will be reset but offset by the m offset
% specified by the previous structure
msum = infostruct(index-1).m;
else
msum = msum + infostruct(index-1).m;
end
% First fold
% If appended to right (not twist)
if infostruct(index).n * infostruct(index).ls + msum <= 2*pi*infostruct(index).r ...
&& name == 0
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
% Ignore left tube line
for i = 6:size(Struct1, 2)
% Factor in offset for every location along the structure
Struct1(i).x = Struct1(i).x + msum + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% If appended to left (not twist)
elseif infostruct(index).n * infostruct(index).ls + msum > 2*pi*infostruct(index).r ...
&& name == 0
% Reassign left tube data to right tube index and specify offsets
Struct1(6).x = Struct1(5).x;
Struct1(6).y = Struct1(5).y;
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
% Ignore the right tube line
for i = 6:size(Struct1, 2)
% Factor in offset for every location along the structure
Struct1(i).x = Struct1(i).x + msum - (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% If appended to right (twist)
elseif infostruct(index).n * infostruct(index).ls + msum <= 2*pi*infostruct(index).r ...
&& name == 1
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
for i = num+1:size(Struct1, 2)
% Factor in offset for every location along the structure
Struct1(i).x = Struct1(i).x + msum + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% If appended to left (twist)
else
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
for i = num+1:size(Struct1, 2)
% Factor in offset for every location along the structure
Struct1(i).x = Struct1(i).x + msum - (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
end
lmax_sum = infostruct(index-1).lmax + lmax_sum;
end
end
if alert == 0 && strcmp(triple, 'triple') == 1
% Include special case for the first block
if index == 1
% No mod term needed
% Do not consider the m offset here, since it will always be 0.
% Be sure to factor in offset from initial frame.
% No twist
if name == 0
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
% Ignore left tube line
for i = 6:size(Struct1, 2)
Struct1(i).x = Struct1(i).x + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% Reassign left tube data to right tube index and specify offsets
Struct2(6).x = Struct2(5).x;
Struct2(6).y = Struct2(5).y;
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct2(i).x = [];
Struct2(i).y = [];
end
% Plot left component of triplet
for i = 6:size(Struct2, 2)
Struct2(i).x = Struct2(i).x - (infostruct(index).n * infostruct(index).ls);
Struct2(i).y = Struct2(i).y;
% Plotting
plot(a, Struct2(i).x, Struct2(i).y, 'color', Struct2(i).color)
end
end
% If appended to right (twist)
if name == 1
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
% Ignore boundary lines
for i = num+1:size(Struct1, 2)
Struct1(i).x = Struct1(i).x + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct2(i).x = [];
Struct2(i).y = [];
end
% Left triplet component
for i = num+1:size(Struct2, 2)
Struct2(i).x = Struct2(i).x - (infostruct(index).n * infostruct(index).ls);
Struct2(i).y = Struct2(i).y;
% Plot each segment with offset
plot(a, Struct2(i).x, Struct2(i).y, 'color', Struct2(i).color)
end
end
% End of index = 1.
else % If index is not equal to 1
% Mod term
if mod(msum + infostruct(index-1).m, 2*pi*infostruct(index).r) ...
< infostruct(index-1).m + msum && mod(msum + infostruct(index-1).m, ...
2*pi*infostruct(index).r) ~= 0
% If the beginning of this structure is over the 2*pi*r limit,
% adjust so that it will be reset but offset by the m offset
% specified by the previous structure
msum = infostruct(index-1).m;
else
msum = msum + infostruct(index-1).m;
end
% First fold
% If not twist
if name == 0
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
% Ignore left tube line
for i = 6:size(Struct1, 2)
% Factor in offset for every location along the structure
Struct1(i).x = Struct1(i).x + msum + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
% Reassign left tube data to right tube index and specify offsets
Struct2(6).x = Struct2(5).x;
Struct2(6).y = Struct2(5).y;
for i = 1:5
% Assign null values for purpose of DXF Generation
Struct2(i).x = [];
Struct2(i).y = [];
end
% Left triplet component
for i = 6:size(Struct2, 2)
% Factor in offset for every location along the structure
Struct2(i).x = Struct2(i).x + msum - (infostruct(index).n * infostruct(index).ls);
Struct2(i).y = Struct2(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment as before, but with offset factored in
plot(a, Struct2(i).x, Struct2(i).y, 'color', Struct2(i).color)
end
end
% Twist
if name == 1
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct1(i).x = [];
Struct1(i).y = [];
end
% Plot on right side
for i = num+1:size(Struct1, 2)
% Factor in offset for every location along the structure
Struct1(i).x = Struct1(i).x + msum + (infostruct(index).n * infostruct(index).ls);
Struct1(i).y = Struct1(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment as before, but with offset factored in
plot(a, Struct1(i).x, Struct1(i).y, 'color', Struct1(i).color)
end
for i = 1:num
% Assign null values for purpose of DXF Generation
Struct2(i).x = [];
Struct2(i).y = [];
end
% Plot left side of triplet
for i = num+1:size(Struct2, 2)
% Factor in left offset
Struct2(i).x = Struct2(i).x + msum - (infostruct(index).n * infostruct(index).ls);
Struct2(i).y = Struct2(i).y + infostruct(index-1).lmax + lmax_sum;
% Plot each segment with offset
plot(a, Struct2(i).x, Struct2(i).y, 'color', Struct2(i).color)
end
end
lmax_sum = infostruct(index-1).lmax + lmax_sum;
end
end
end