-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrigami_Elbow_CreasePattern.m
724 lines (522 loc) · 19.4 KB
/
Origami_Elbow_CreasePattern.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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
% Graph for crease pattern - Origami elbow fitting
% Last edited 6/8/2021 by Lucien Peach
function [dataFoldA, m, lmax] = Origami_Elbow_CreasePattern(lengths, ls, n, h1, h2, r, phi, theta, mirror, split, tuckangle)
% Create "duplicate" value
duplicate = 1;
% Define theta_original
theta_original = theta;
% Check value of theta
if theta > pi/2 && strcmp(split, 'off') ~= 1
duplicate = 2;
end
% Counter used for data structure indexing
count = 1;
% Identify colors
orange = [1, 0.41, 0];
% red = [1, 0, 0];
blue = [0, 0, 1];
black = [0, 0, 0];
% Specifying boundary for sheet - in 4 parts
% -------------------------------------------------------------------
% Determine max value of lengths array
lmax = max(lengths);
% Determine if the layer needs to be duplicated or not
if duplicate == 1
% Overall boundary
boundarybottom = [0, 0; n*ls, 0];
boundaryleft = [0, 0; 0, h1 + 2*lmax + h2];
boundarytop = [0, h1 + 2*lmax + h2; n*ls, h1 + 2*lmax + h2];
boundaryright = [n*ls, h1 + 2*lmax + h2; n*ls, 0];
else
% Overall boundary
boundarybottom = [0, 0; n*ls, 0];
boundaryleft = [0, 0; 0, h1 + 4*lmax + h2];
boundarytop = [0, h1 + 4*lmax + h2; n*ls, h1 + 4*lmax + h2];
boundaryright = [n*ls, h1 + 4*lmax + h2; n*ls, 0];
end
% Log data to structure and add to plot
dataFoldA(count).x = boundarybottom(:, 1);
dataFoldA(count).y = boundarybottom(:, 2);
dataFoldA(count).color = black;
figure()
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
hold on
set(gcf, 'color', 'w')
count = count + 1;
dataFoldA(count).x = boundaryleft(:, 1);
dataFoldA(count).y = boundaryleft(:, 2);
dataFoldA(count).color = black;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
count = count + 1;
dataFoldA(count).x = boundarytop(:, 1);
dataFoldA(count).y = boundarytop(:, 2);
dataFoldA(count).color = black;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
count = count + 1;
dataFoldA(count).x = boundaryright(:, 1);
dataFoldA(count).y = boundaryright(:, 2);
dataFoldA(count).color = black;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
% Increase count
count = count + 1;
dataFoldA(count).x = boundaryleft(:, 1);
dataFoldA(count).y = boundaryleft(:, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
count = count + 1;
dataFoldA(count).x = boundaryright(:, 1);
dataFoldA(count).y = boundaryright(:, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
% Begin by specifying proximal and distal horizontal lines
% -------------------------------------------------------------------
% % Store proximal to array
% proximalx = [0; n*ls];
% proximaly = [h1; h1];
% dataFoldA(count).x = proximalx;
% dataFoldA(count).y = proximaly;
% dataFoldA(count).color = red;
%
% % Begin plot. Plot proximal line
% plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
% dataFoldA(count).color);
% hold on
% set(gcf, 'color', 'w');
%
% % Increase counter
% count = count + 1;
%
% % Store distal to array
% distalx = [0; n*ls];
% distaly = [h1 + 2*lmax; h1 + 2*lmax];
% dataFoldA(count).x = distalx;
% dataFoldA(count).y = distaly;
% dataFoldA(count).color = red;
%
% % Plot distal line
% plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
% dataFoldA(count).color);
%
% % Increase count
% count = count + 1;
% Specify line pattern created by lengths
% ------------------------------------------------------------------
% Increase count
count = count + 1;
if duplicate == 1
% Initialize midsection array
midsection = zeros(n+1, 2);
% Store each length value to array. Loop.
% X coordinates
for i = 1:n+1
midsection(i, 1) = (i-1) * ls;
end
% Y coordinates
for j = 1:n+1
if j < n+1
midsection(j, 2) = lengths(j, 1) + h1;
else
midsection(j, 2) = midsection(1, 2);
end
end
% % Log data for final point (extra column for folding)
% midsection(n+2, 1) = (n+1)*ls;
% midsection(n+2, 2) = midsection(2, 2);
else
% Initialize duplication midsection
midsection = zeros(2*(n+1), 2);
% Store each length value to array. Loop.
% X coordinates
for i = 1:n+1
midsection(i, 1) = (i-1) * ls;
end
midsection(n+2:2*(n+1), 1) = midsection(1:n+1, 1);
% Y coordinates
for j = 1:n+1
if j < n+1
midsection(j, 2) = lengths(j, 1) + h1;
else
midsection(j, 2) = midsection(1, 2);
end
end
midsection(n+2:2*(n+1), 2) = midsection(1:n+1, 2) + 2*lmax;
end
% Log data to structure
dataFoldA(count).x = midsection(1:n+1, 1);
dataFoldA(count).y = midsection(1:n+1, 2);
dataFoldA(count).color = blue;
% Express midsection pattern
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
% Counter
count = count + 1;
% Log data to structure
dataFoldA(count).x = midsection(n+2:end, 1);
dataFoldA(count).y = midsection(n+2:end, 2);
dataFoldA(count).color = blue;
% Express midsection pattern
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
% Mirror (Optional)
% ------------------------------------------------------------------
if strcmp(mirror, 'on') == 1
if duplicate == 1
% Counter
count = count + 1;
% Mirror lengths region
mirrormid = zeros(n+1, 2);
% Store each length value to array. Loop.
% X coordinates
for i = 1:n+1
mirrormid(i, 1) = (i-1) * ls;
end
% Y coordinates
for j = 1:n+1
if j < n+1
mirrormid(j, 2) = -lengths(j, 1) + h1 + 2*lmax;
else
mirrormid(j, 2) = mirrormid(1, 2);
end
end
% Log data to structure
dataFoldA(count).x = mirrormid(:, 1);
dataFoldA(count).y = mirrormid(:, 2);
dataFoldA(count).color = blue;
% Express midsection pattern
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
else
% Counter
count = count + 1;
% Mirror lengths region
mirrormid = zeros(2*(n+1), 2);
% Store each length value to array. Loop.
% X coordinates
for i = 1:n+1
mirrormid(i, 1) = (i-1) * ls;
end
mirrormid(n+2:2*(n+1), 1) = mirrormid(1:n+1, 1);
% Y coordinates
for j = 1:n+1
if j < n+1
mirrormid(j, 2) = -lengths(j, 1) + h1 + 2*lmax;
else
mirrormid(j, 2) = mirrormid(1, 2);
end
end
mirrormid(n+2:2*(n+1), 2) = mirrormid(1:n+1, 2) + 2*lmax;
% Log data to structure
dataFoldA(count).x = mirrormid(1:n+1, 1);
dataFoldA(count).y = mirrormid(1:n+1, 2);
dataFoldA(count).color = blue;
% Express midsection pattern
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
% Increase count
count = count + 1;
dataFoldA(count).x = mirrormid(n+2:2*(n+1), 1);
dataFoldA(count).y = mirrormid(n+2:2*(n+1), 2);
dataFoldA(count).color = blue;
% Plot duplication layer
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
end
% Specify boundary of hidden section
% ------------------------------------------------------------------
% Increase count
count = count + 1;
if duplicate == 1
% Store hidden to array
hiddenx = [0; n*ls];
hiddeny = [h1 + lmax; h1 + lmax];
dataFoldA(count).x = hiddenx;
dataFoldA(count).y = hiddeny;
dataFoldA(count).color = orange;
% Plot bottom boundary of midsection
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
else
% Store hidden to array
hiddenx = [0; n*ls];
hiddeny = [h1 + lmax; h1 + lmax];
dataFoldA(count).x = hiddenx;
dataFoldA(count).y = hiddeny;
dataFoldA(count).color = orange;
% Plot bottom boundary of midsection
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
% Increase count
count = count + 1;
% Store hidden2 to array
hiddenx = [0; n*ls];
hiddeny = [h1 + 3*lmax; h1 + 3*lmax];
dataFoldA(count).x = hiddenx;
dataFoldA(count).y = hiddeny;
dataFoldA(count).color = orange;
% Plot bottom boundary of midsection
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
% Specify vertical segments of hidden section
% ------------------------------------------------------------------
if duplicate == 1
% Initialize hidden vertical line array
hiddenmid = zeros(2*(n-1), 2);
% Loop through to store [x,y] pairs for each line segment
for k = 0:2:(2*n)-4
% Increase count initially
count = count + 1;
% Indexing
index = (k/2) + 2;
% Store x coordinates for each segment
hiddenmid(k+1, 1) = (index-1) * ls;
hiddenmid(k+2, 1) = (index-1) * ls;
% Store y coordinates for each segment
hiddenmid(k+1, 2) = lengths(index, 1) + h1;
hiddenmid(k+2, 2) = h1 + lmax;
% Store to data array
dataFoldA(count).x = hiddenmid(k+1:k+2, 1);
dataFoldA(count).y = hiddenmid(k+1:k+2, 2);
dataFoldA(count).color = orange;
% Plot bottom boundary of midsection
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
else
% Initialize hidden vertical line array
hiddenmid = zeros(2*(2*(n-1)), 2);
% Loop through to store [x,y] pairs for each line segment
for k = 0:2:(2*n)-4
% Increase count initially
count = count + 1;
% Indexing
index = (k/2) + 2;
% Store x coordinates for each segment
hiddenmid(k+1, 1) = (index-1) * ls;
hiddenmid(k+2, 1) = (index-1) * ls;
% Store y coordinates for each segment
hiddenmid(k+1, 2) = lengths(index, 1) + h1;
hiddenmid(k+2, 2) = h1 + lmax;
% Store to data array
dataFoldA(count).x = hiddenmid(k+1:k+2, 1);
dataFoldA(count).y = hiddenmid(k+1:k+2, 2);
dataFoldA(count).color = orange;
% Plot bottom boundary of midsection
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
hiddenmid(2*(n-1)+1:end, 1) = hiddenmid(1:2*(n-1), 1);
hiddenmid(2*(n-1)+1:end, 2) = hiddenmid(1:2*(n-1), 2) + 2*lmax;
for i = 2*(n-1)+1:2:4*(n-1)-1
% counter
count = count + 1;
% Store to data array
dataFoldA(count).x = hiddenmid(i:i+1, 1);
dataFoldA(count).y = hiddenmid(i:i+1, 2);
dataFoldA(count).color = orange;
% Plot
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
end
% Bottom tube folds
% --------------------------------------------------------------------
if duplicate == 1
% Bottom tube folds and graphing
bottomtube = zeros(2*(n-1), 2);
% Ignore side folds as these are graphed by the boundary section
for ii = 0:2:(2*n)-4
% Increase count initially
count = count + 1;
% Indexing
index = ((ii)/2) + 2;
% Populate array
bottomtube(ii+1, 1) = (index-1)*ls;
bottomtube(ii+1, 2) = 0;
bottomtube(ii+2, 1) = (index-1)*ls;
bottomtube(ii+2, 2) = lengths(index, 1) + h1;
% Log data to structure and add to plot. Plotting is sequential
dataFoldA(count).x = bottomtube(ii+1:ii+2, 1);
dataFoldA(count).y = bottomtube(ii+1:ii+2, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
else
% Bottom tube folds and graphing
bottomtube = zeros(2*(2*(n-1)), 2);
% Ignore side folds as these are graphed by the boundary section
for ii = 0:2:(2*n)-4
% Increase count initially
count = count + 1;
% Indexing
index = ((ii)/2) + 2;
% Populate array
bottomtube(ii+1, 1) = (index-1)*ls;
bottomtube(ii+1, 2) = 0;
bottomtube(ii+2, 1) = (index-1)*ls;
bottomtube(ii+2, 2) = lengths(index, 1) + h1;
% Log data to structure and add to plot. Plotting is sequential
dataFoldA(count).x = bottomtube(ii+1:ii+2, 1);
dataFoldA(count).y = bottomtube(ii+1:ii+2, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
% For duplication
bottomtube(2*(n-1)+1:end, 1) = bottomtube(1:2*(n-1), 1);
bottomtube(2*(n-1)+1:2:end, 2) = bottomtube(1:2:2*(n-1), 2) + 2*lmax + h1;
bottomtube(2*(n-1)+2:2:end, 2) = bottomtube(2:2:2*(n-1), 2) + 2*lmax;
% Ignore side folds as these are graphed by the boundary section
for i = 2*(n-1)+1:2:2*(2*(n-1))-1
% counter
count = count + 1;
% Log data to structure and add to plot. Plotting is sequential
dataFoldA(count).x = bottomtube(i:i+1, 1);
dataFoldA(count).y = bottomtube(i:i+1, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
end
% Top tube folds
% --------------------------------------------------------------------
if duplicate == 1
% Top tube folds and graphing
toptube = zeros(2*(n-1), 2);
% Ignore side folds as these are graphed by the boundary section
for jj = 0:2:(2*n)-4
% Increase count initially
count = count + 1;
% Indexing
index = (jj/2) + 2;
% Populate array
toptube(jj+1, 1) = (index-1)*ls;
toptube(jj+1, 2) = lmax + h1;
toptube(jj+2, 1) = (index-1)*ls;
toptube(jj+2, 2) = 2*lmax + h1 + h2;
% Log data to structure and add to plot. Plotting is sequential
dataFoldA(count).x = toptube(jj+1:jj+2, 1);
dataFoldA(count).y = toptube(jj+1:jj+2, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
else
% Top tube folds and graphing
toptube = zeros(2*(2*(n-1)), 2);
% Ignore side folds as these are graphed by the boundary section
for jj = 0:2:(2*n)-4
% Increase count initially
count = count + 1;
% Indexing
index = (jj/2) + 2;
% Populate array
toptube(jj+1, 1) = (index-1)*ls;
toptube(jj+1, 2) = lmax + h1;
toptube(jj+2, 1) = (index-1)*ls;
toptube(jj+2, 2) = 2*lmax + h1;
% Log data to structure and add to plot. Plotting is sequential
dataFoldA(count).x = toptube(jj+1:jj+2, 1);
dataFoldA(count).y = toptube(jj+1:jj+2, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
% Add duplication data
toptube(2*(n-1)+1:end, 1) = toptube(1:2*(n-1), 1);
toptube(2*(n-1)+1:2:end, 2) = toptube(1:2:2*(n-1), 2) + 2*lmax;
toptube(2*(n-1)+2:2:end, 2) = toptube(2:2:2*(n-1), 2) + 2*lmax + h2;
% Loop to plot
for i = 2*(n-1)+1:2:2*(2*(n-1))-1
% counter
count = count + 1;
% Log data to structure and add to plot. Plotting is sequential
dataFoldA(count).x = toptube(i:i+1, 1);
dataFoldA(count).y = toptube(i:i+1, 2);
dataFoldA(count).color = blue;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
end
% Tuck Angle Additions
% -----------------------------------------------------------------------
% First, find the tucklengths vector that will contain the tucklength
% values, calculated using the value of max(lengths) as well as the
% individual length segments.
tucklengths = zeros(n+1, 1);
for i = 1:n+1
tucklengths(i, 1) = max(lengths) - lengths(i, 1);
end
% Using this value as well as the values contained within tuckangle, we can
% determine the "hidden region" of the schematic
tuckoffsets = zeros(n, 1);
for i = 1:n
tuckoffsets(i, 1) = tan(tuckangle(i, 1))*tucklengths(i, 1);
end
% We can now use this array to print the overlap region for the print
% schematic for the elbow joint
tuckarray = zeros(3*n, 2);
for i = 1:n
% Array index initialization
index = (i-1)*3 + 1;
% Increase count
count = count + 1;
% Storing plotting points to array
tuckarray(index, 1) = (i-1)*ls;
tuckarray(index, 2) = lengths(i, 1) + h1;
tuckarray(index+1, 1) = ((i-1)*ls) + tuckoffsets(i);
tuckarray(index+1, 2) = max(lengths) + h1;
tuckarray(index+2, 1) = (i-1)*ls;
tuckarray(index+2, 2) = 2*max(lengths) - lengths(i, 1) + h1;
% Storing to DataStruct and plotting
dataFoldA(count).x = tuckarray(index:index+2, 1);
dataFoldA(count).y = tuckarray(index:index+2, 2);
dataFoldA(count).color = orange;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
% Create the array for the secondary level, if needed, by adding
% 2*max(lengths) to all values of the primary level
if duplicate == 2
% Initialize array
newtuckarray = zeros(size(tuckarray, 1), 2);
% Populate new array
for i = 1:size(tuckarray, 1)
newtuckarray(i, 1) = tuckarray(i, 1);
newtuckarray(i, 2) = tuckarray(i, 2) + 2*max(lengths);
end
% Store array data to structure and plot
for i = 1:n
count = count + 1;
index = (i-1)*3 + 1;
dataFoldA(count).x = newtuckarray(index:index+2, 1);
dataFoldA(count).y = newtuckarray(index:index+2, 2);
dataFoldA(count).color = orange;
plot(dataFoldA(count).x, dataFoldA(count).y, 'color', ...
dataFoldA(count).color)
end
end
% Plotting Options
% ----------------------------------------------------------------------
% Label the plot for clarity
title({
('Origami Schematic A for Provided Parameters:')
['[r = ' num2str(r) ', n = ' num2str(n) ', phi = ' num2str(phi) ', theta = ' num2str(theta_original) ']']
})
daspect([1 1 1])
m = 0;
if duplicate == 1
lmax = h1 + 2*lmax + h2;
else
lmax = h1 + 4*lmax + h2;
end
close
end