-
Notifications
You must be signed in to change notification settings - Fork 0
/
prMachines.js
executable file
·1767 lines (1462 loc) · 55.8 KB
/
prMachines.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
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////
// This is the more-or-less well-commented version of the Proportion Library's "machines" class.
// (c)2013 Neal McDonald, released under MIT License
// Use it however you like; have a nice day.
// There is only one class in this file. It defines the prMachines class, which provides functions
// All the functions implement machines or test them.
// All of the machines operate on a construction, only by adding to it.
// They all return dictionaries.
// The names of the elements ID the parts of the result.
// The outputs are CapitalizedCamelCase.
// The machine object should maintain a "GroupID" member, and when a machine adds to a construction,
// it should use that group number?
// The machines should return everything they make? so that you can duplicate construction elements
// as little as possible?
// The machines should add as little to the drawing as possible.
// The challenge of these objects:
// 1) to take input from a complex document in a simple way.
// 2) to return complex information in a standard way.
// 3) Nomenclature! To be useful, the machines must allow you to refer to the things they return, inside the
// drawing, but not clutter up the main program of the drawing-- to provide control over the scope of the
// naming of parts of a construction. When the dictionaries are deleted, the objects they refer to are still
// part of the construction, but they become much harder to access.
// This library extends proportion.js, and therefore does require it.
function prMachines(pg) {
this.pg = pg; // the page in which the machines will operate
}
prMachines.prototype = {
// given p1 and p2, two points, and pAbove, a point defining "above", returns
// "Connector", the line containing p1 and p2
// "MidPt", the midpoint of the line segment connecting p1 and p2,
// "MidLine", the line perpendicular to Connector at MidPt
// "C1" and "C2" the circles at p1 and p2, through p2 and p1
// "I1" and "I2", the points where C1 and C2 intersect, where I1 is closer to "above"
midpoint: function(p1, p2, pAbove) {
var c1 = this.pg.circle(p1, p2);
var c2 = this.pg.circle(p2, p1);
var int1 = this.pg.first(c1, c2, pAbove);
var int2 = this.pg.second(c1, c2, pAbove);
var midLine = this.pg.line(int1, int2);
var conr = this.pg.line(p1, p2);
var midpt = this.pg.first(midLine, conr, pAbove);
var result = {"MidPoint":midpt, "MidLine":midLine, "Connector":conr, "I1":int1, "I2":int2, "C1":c1, "C2":c2};
return result;
},
midpoint_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.3);
var p2 = this.pg.given(0.5,0.2);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9);
var md = this.midpoint(pA, pB, pC);
},
// given p1 and p2, two points, and pAbove, a third point, returns,
// "Connector", the line through p1 and p2
// "Perpendicular", the line perpendicular to Connector through p1
// "C1" the circle at p1 through p2
// "P3" the line on Connector and C1, opposite p2
// "C2" and "C3", the circles around p2 and P3, through P3 and P2
// "PUp" and "PDown", the points where Perpendicular, C1, and C2 intersect,
// where pUp is the intersection closer to "pAbove"
perpendicular: function(p1, p2, pAbove) {
var c1 = this.pg.circle(p1, p2);
var conector = this.pg.line(p1, p2);
var p3 = this.pg.second(conector, c1, p2);
var mids = this.midpoint(p3, p2, pAbove);
var result = {"Perpendicular":mids.MidLine,
"Connector":mids.Connector,
"P3":p3,
"PUp":mids.I1,
"PDown":mids.I2,
"C1":c1,
"C2":mids.C1,
"C3":mids.C2
};
return result;
},
perpendicular_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.3);
var p2 = this.pg.given(0.5,0.2);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9);
var md = this.perpendicular(pA,pB, pC);
},
goldenRatio: function(p1, p2, pAbove) {
var perps = this.perpendicular(p2,p1,pAbove);
var c1 = this.pg.circle(p1,p2);
var pHi = this.pg.first(c1,perps.C1,pAbove);
var pLo = this.pg.second(c1,perps.C1,pAbove);
var midLn = this.pg.line(pHi, pLo);
var midPt = this.pg.first(midLn, perps.Connector, pAbove);
var cMid = this.pg.circle(p2,midPt);
var triHi = this.pg.first(cMid,perps.Perpendicular, pAbove);
var hyp = this.pg.line(p1,triHi);
var cHi = this.pg.circle(triHi, p2);
var pRat = this.pg.first(cHi,hyp,p1);
var cRat = this.pg.circle(p1,pRat);
var pG = this.pg.first(perps.Connector,cRat, pRat);
var result = {
"P1":p1, "P2":p2, "PG":pG, "CG":cRat,
"PMid":midPt, "LMid":midLn, "CMid":cMid,
"Perpendicular":perps.Perpendicular, "Connector":perps.Connector,
"C1":c1, "C2":perps.C1, "Hypotenuse":hyp
};
return result;
},
goldenRatio_test: function(t) {
// var pA = this.pg.given(0.5,0.5);
// var pB = this.pg.given(0.5,0.2);
// var pC = this.pg.given(0.9,0.1);
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.43);
var p2 = this.pg.given(0.5,0.36);
var p3 = this.pg.given(0.5,0.07);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.goldenRatio(pA,pB,pC);
},
// given p1 and p2, two points, and t, a line or circle
// return n points, each named "P1" through "Pn", equally spaced, on t
// and n circles, each named "C1"-"Cn"
// P1 = p1, p2 = p2
series: function(n, p1,p2, t) {
var i;
var c1 = this.pg.circle(p1, p2);
var Ci, Pi, Pim, Pip, Cname, Pname;
Pim = p1; // p(i-1)
Pi = p2; // pi
var result = {"P1":p1, "C1":c1};
for (i=2; i<(n+1); i=i+1) {
Cname = "C" + i;
Pname = "P" + i;
Ci = this.pg.circle(Pi, Pim);
Pip = this.pg.second(t, Ci, Pim); // p(i+1)=Pip
result[Pname] = Pi;
result[Cname] = Ci;
Pim = Pi;
Pi = Pip;
}
return result;
},
series_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.25);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9);
var l1 = this.pg.line(pC, pB);
var md = this.series(10, pC, pB, l1);
},
// given p1 and p2, two points,
// return n points, each named "P1" through "Pn", equally spaced,
// on the line connecting p1 and p2
// and n circles, each named "C1"-"Cn"
// P1 = p1, p2 = p2
subdivide: function(n, p1,p2) {
var c1 = this.pg.circle(p1,p2);
var c2 = this.pg.circle(p2,p1);
var conn = this.pg.line(p1,p2);
var pUp = this.pg.first(c1,c2, p1); // don't know or care which we get
var pDn = this.pg.second(c1,c2, p1); // as long as this is the other one
var ln1 = this.pg.line(p1,pUp);
var ln2 = this.pg.line(p2,pDn);
// getting a smaller length than p1-p2 would improve accuracy
// not a concern yet.
var ser1 = this.series(n, p1,pUp, ln1);
var ser2 = this.series(n, p2,pDn, ln2);
var result = {"P1":p1, "Connector":conn };
var i, backwards, name1, name2, pA, pB, lnC, pC;
for (i=2; i<=n; i=i+1) {
backwards = (n+2)-i;
name1 = "P" + i;
name2 = "P" + backwards;
pA = ser1[name1];
pB = ser2[name2];
lnC = this.pg.line(pA,pB);
pC = this.pg.first(lnC, conn, p1);
result[name1] = pC;
}
return result;
},
subdivide_test: function(t) {
// var pA = this.pg.given(0.3,0.5);
// var pB = this.pg.given(0.7,0.5);
var p0 = this.pg.given(0.5,0.5);
var p2 = this.pg.given(0.5,0.05);
var p3 = this.pg.given(0.5,0.1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c2, t*1.1);
var pB = this.pg.addParametricPoint(c3, t*.9);
var l1 = this.subdivide(5, pA, pB);
},
// given p1 and p2 defining a circle, a third point p3, outside the circle,
// and a fourth point, pAbove,
// return L1 and L2, the two lines tangent to the circle through the point,
// and PT1 and PT2, the two tangent points.
// PT1 is the tangent point closest to pAbove
tangents: function(p1,p2,p3, pAbove) {
var mids = this.midpoint(p1, p3, pAbove);
var midPt = mids.MidPoint;
var c1 = this.pg.circle(p1,p2);
var c2 = this.pg.circle(midPt, p1); // circle at p1 through p3
var pt1 = this.pg.first(c1, c2, pAbove);
var pt2 = this.pg.second(c1, c2, pAbove);
var l1 = this.pg.line(p3,pt1);
var l2 = this.pg.line(p3,pt2);
var result = {"L1":l1, "L2":l2, "PT1":pt1, "PT2":pt2};
return result;
},
tangents_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var pAbove = this.pg.given(0.1,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.tangents(pA,pB,pC, pAbove);
},
// given points p1,p2,and p3, defining an angle p1,p2,p3,
// (p2 being the intersection of thelines p1-p2 and p2-p3),
// return a line "Bisector", through points p2 and P4, that
// bisects p1p2p3.
angleBisection: function(p1,p2,p3, pAbove) {
var ln1 = this.pg.line(p2, p1);
var ln3 = this.pg.line(p2, p3);
var c1 = this.pg.circle(p2, p1);
var eqp3 = this.pg.first(c1, ln3, p3);
var midpoint = this.midpoint(p1, eqp3, pAbove);
var result = {"Bisector":midpoint.MidLine, "MidPoint":midpoint.MidPoint};
return result;
},
angleBisection_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var pAbove = this.pg.given(0.1,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.angleBisection(pA,pB,pC,pAbove);
},
/////////////////////// equilateral triangles
// triInCircle: use hexagonInCircle; minimal hex construction is the same
// triOnLine: use midpoint; result is p1, p2, mids["I1"];
equilateralOnLine: function(p1, p2, pAbove) {
var c1 = this.pg.circle(p1, p2);
var c2 = this.pg.circle(p2, p1);
var p3 = this.pg.first(c1, c2, pAbove);
var result = {
"P1":p1, "P2":p2, "P3":p3, "C1":c1, "C2":c2};
return result;
},
equilateralOnLine_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var pAbove = this.pg.given(0.1,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.midpoint(pA, pB, pC);
},
// triAcrossLine: use hex
// From Euclid! How to make a circle around a point (p1) that has the
// same radius as a first circle (p2,p3)
circleTransfer: function(p1, pc1, pc2) {
var c23 = this.pg.circle(pc1, pc2); // to be transferred
var c12 = this.pg.circle(p1,pc1);
var c21 = this.pg.circle(pc1,p1); // to make an equilateral triangle
var p4 = this.pg.first(c12,c21,pc2); // doesn't matter which
var ln41 = this.pg.line(p4,p1);
var ln42 = this.pg.line(p4,pc1);
var p1Ext = this.pg.second(c23, ln42, p4); // dist p4-p1Ext= p2-p3 + p1-p2
var cExt = this.pg.circle(p4, p1Ext);
var p5 = this.pg.first(cExt, ln41, p1);
var cGoal = this.pg.circle(p1,p5);
var result = {
"P1":p1, "PC1":pc1, "PC2":pc2, "PEq":p4, "C1":c12, "C2":c21, "CNew":cGoal};
return result;
},
circleTransfer_test: function(t) {
// var pA = this.pg.given(0.5,0.5);
// var pB = this.pg.given(0.3,0.4);
// var pC = this.pg.given(0.3,0.3);
this.pg.setGroupColor(2, "#00f");
var p0 = this.pg.given(0.4,0.5);
var p1 = this.pg.given(0.4,0.4);
var p2 = this.pg.given(0.5,0.5);
var p3 = this.pg.given(0.5,0.4);
var p4 = this.pg.given(0.6,0.5);
var p5 = this.pg.given(0.6,0.4);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p2,p3);
var c3 = this.pg.circle(p4,p5);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.circleTransfer(pA, pB, pC);
this.pg.setGroup(md.CNew, 2);
},
sublimeTriangleFromLong: function(p1, p2, pAbove) {
var gr = this.goldenRatio(p1,p2,pAbove);
gr["P3"] = this.pg.first(gr.CG, gr.C2, pAbove);
// Fie, Javascript! Thou host and font of barbarism!
return gr;
},
sublimeTriangleFromLong_test: function(t) {
// var pA = this.pg.given(0.5,0.5);
// var pB = this.pg.given(0.5,0.2);
// var pC = this.pg.given(0.9,0.1);
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.43);
var p2 = this.pg.given(0.5,0.36);
var p3 = this.pg.given(0.5,0.07);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.sublimeTriangleFromLong(pA,pB,pC);
},
sublimeTriangleFromShort: function(p1, p2, pAbove) {
var stl = this.sublimeTriangleFromLong(p1,p2,pAbove);
var ln13 = this.pg.line(stl.P3,p1);
var newP3 = this.pg.first(ln13,stl.LMid, pAbove);
stl["P4"] = stl.P3;
stl["P3"] = newP3;
return stl;
},
sublimeTriangleFromShort_test: function(t) {
// var pA = this.pg.given(0.5,0.5);
// var pB = this.pg.given(0.5,0.3);
// var pC = this.pg.given(0.9,0.1);
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.43);
var p2 = this.pg.given(0.5,0.36);
var p3 = this.pg.given(0.5,0.07);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.sublimeTriangleFromShort(pA,pB,pC);
},
/////////////////////// squares
/////////////////////// squares
/////////////////////// squares
// ngon in circle returns, not the sides, but the corners, and the
// circles that generated them
squareInCircle: function(p0, p12, pAbove) {
var c0 = this.pg.circle(p0, p12);
var c12 = this.pg.circle(p12, p0); // naming after hours on clock face
var l1 = this.pg.line(p0,p12);
var p6 = this.pg.second(c0,l1, p12);
var c6cr = this.pg.circle(p6, p12);
var c12cr = this.pg.circle(p12, p6);
var p3cr = this.pg.first(c6cr, c12cr, pAbove);
var p9cr = this.pg.second(c6cr, c12cr, pAbove);
var crossLine = this.pg.line(p3cr, p9cr);
var p3 = this.pg.first(c0, crossLine, pAbove);
var p9 = this.pg.second(c0, crossLine, pAbove);
var result = {
"P1":p12, "P2":p3, "P3":p6, "P4":p9,
"C0":c0, "C1":c12, "L13":l1, "L24":crossLine
};
return result;
},
squareInCircle_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.squareInCircle(pA, pB, pC);
},
// two points => square using them as a side
squareOnLine: function(p1, p2, pAbove) {
var c1 = this.pg.circle(p1, p2);
var c2 = this.pg.circle(p2, p1);
var ln01 = this.pg.line(p1,p2);
var p0 = this.pg.second(c1, ln01, p2);
var p3 = this.pg.second(c2, ln01, p1); // next points out on line
var c02 = this.pg.circle(p0,p2);
var c20 = this.pg.circle(p2,p0);
var c13 = this.pg.circle(p1,p3);
var c31 = this.pg.circle(p3,p1); // circles for perpendiculars
var pHigh1 = this.pg.first(c02,c20,pAbove);
var pHigh2 = this.pg.first(c13,c31,pAbove);
var ln1 = this.pg.line(p1,pHigh1);
var ln2 = this.pg.line(p2,pHigh2); // perpendicular lines
var pUp1 = this.pg.first(ln1,c1,pAbove);
var pUp2 = this.pg.first(ln2,c2,pAbove); // the other corners
var ln3 = this.pg.line(pUp1,pUp2);
var result = {
"P1":p1, "P2":p2, "P3":pUp2, "P4":pUp1,
"L12":ln01, "L23":ln2, "L34":ln3, "L41":ln1,
"C1":c1, "C2":c2
};
return result;
},
squareOnLine_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.squareOnLine(pA, pB, pC);
},
// two points => line => square for which the line is a diagonal
squareAcrossLine: function(p1, p3, pAbove) {
var mids = this.midpoint(p1,p3,pAbove);
// {"MidPoint":midpt, "MidLine":midLine, "Connector":conr, "I1":int1, "I2":int2, "C1":c1, "C2":c2};
var pmid = mids.MidPoint;
var lnmid = mids.MidLine;
var cMid = this.pg.circle(pmid, p1);
var p2 = this.pg.first(cMid,lnmid, pAbove);
var p4 = this.pg.second(cMid,lnmid, pAbove);
var result = {
"P1":p1, "P2":p2, "P3":p3, "P4":p4,
"L13":mids.Connector, "LN24":lnmid, "C1":mids.C1, "C2":mids.C2
};
return result;
},
squareAcrossLine_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.squareAcrossLine(pA, pB, pC);
},
/////////////////////// parallelograms
///////////////////////
///////////////////////
// given 3 points, add a 4th that make a parallelogram.
// but there are 4 possible ||grams for any triangle!
// find p4 that is on the opposite side of the line p1,p3
completeParallelogram: function(p1,p2,p3) {
var mid = this.midpoint(p1,p3,p2);
// var result = {"MidPoint":midpt, "MidLine":midLine, "Connector":conr, "I1":int1, "I2":int2, "C1":c1, "C2":c2};
var midPt = mid.MidPoint;
var midline = this.pg.line(p2,midPt);
var cFinder = this.pg.circle(midPt,p2);
var p4 = this.pg.second(cFinder,midline,p2);
var result = { "P1":p1, "P2":p2, "P3":p3, "P4":p4 };
return result;
},
completeParallelogram_test: function(t) {
var p0 = this.pg.given(0.4,0.5);
var p1 = this.pg.given(0.4,0.3);
var p2 = this.pg.given(0.5,0.5);
var p3 = this.pg.given(0.5,0.3);
var p4 = this.pg.given(0.6,0.5);
var p5 = this.pg.given(0.6,0.3);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p2,p3);
var c3 = this.pg.circle(p4,p5);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.completeParallelogram(pA, pB, pC);
var ln1 = this.pg.line(md.P1, md.P2);
var ln1 = this.pg.line(md.P1, md.P4);
var ln1 = this.pg.line(md.P3, md.P2);
var ln2 = this.pg.line(md.P3, md.P4);
},
/////////////////////// golden rectangles
/////////////////////// golden rectangles
/////////////////////// golden rectangles
// two points-> line -> golden rectangle from the square defined by those two lines,
// extended along the line.
goldenOnLine1: function(p1,p2, pAbove) {
var ln1 = this.pg.addLine(p1, p2); // draw a line through them
var c1 = this.pg.addCircle(p1, p2); // draw circles thru both both ways
var c2 = this.pg.addCircle(p2, p1);
var p3 = this.pg.addSecondIntersection(c1, ln1, p2); // points on the outside
var p4 = this.pg.addSecondIntersection(c2, ln1, p1);
var c3 = this.pg.addCircle(p3, p2); // big circles
var c4 = this.pg.addCircle(p1, p4);
var c5 = this.pg.addCircle(p2, p3);
var c6 = this.pg.addCircle(p4, p1);
var p5 = this.pg.addSecondIntersection(c1, c2, p4); // gives the lower of the two
var p6 = this.pg.addFirstIntersection(c5, c3, p5);
var p7 = this.pg.addFirstIntersection(c6, c4, p5);
var p8 = this.pg.addFirstIntersection(c1, c2, p4);
var ln2 = this.pg.addLine(p1, p6);
var ln3 = this.pg.addLine(p2, p7);
var ln4 = this.pg.addLine(p5, p8);
var p9 = this.pg.addFirstIntersection(c1, ln2, p5);
var p10 = this.pg.addFirstIntersection(c2, ln3, p5);
var ln5 = this.pg.addLine(p9, p10); // lower edge
var p11 = this.pg.addFirstIntersection(ln1, ln4, p5); // paydirt
var p12 = this.pg.addFirstIntersection(ln5, ln4, p5);
var c7 = this.pg.addCircle(p11, p10);
var c8 = this.pg.addCircle(p12, p2);
var p13 = this.pg.addFirstIntersection(c7, ln1, p4);
var p14 = this.pg.addFirstIntersection(c8, ln5, p4);
var ln6 = this.pg.addLine(p13, p14);
var res = { "P1":p1, "P2":p2, "P3":p3, "P4":p4 };
return res;
},
goldenOnLine_test: function(t) {
var p0 = this.pg.given(0.4,0.5);
var p1 = this.pg.given(0.4,0.3);
var p2 = this.pg.given(0.5,0.5);
var p3 = this.pg.given(0.5,0.3);
var p4 = this.pg.given(0.6,0.5);
var p5 = this.pg.given(0.6,0.3);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p2,p3);
var c3 = this.pg.circle(p4,p5);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.goldenOnLine1(pA, pB, pC);
var ln1 = this.pg.line(md.P1, md.P2);
var ln1 = this.pg.line(md.P1, md.P4);
var ln1 = this.pg.line(md.P3, md.P2);
var ln2 = this.pg.line(md.P3, md.P4);
},
// puts the short side on the line
goldenOnLine2: function(p1,p2, pAbove) {
var ln1 = this.pg.line(p1, p2); // draw a line through them
var c1 = this.pg.circle(p1, p2); // draw circles thru both both ways
var c2 = this.pg.circle(p2, p1);
var pOuter1 = this.pg.second(c1, ln1, p2); // points on the outside
var pOuter2 = this.pg.second(c2, ln1, p1);
var cb1a = this.pg.circle(pOuter1, p2); // perp lines thru p1 p2
var cb1b = this.pg.circle(p2, pOuter1);
var cb2a = this.pg.circle(p1, pOuter2);
var cb2b = this.pg.circle(pOuter2, p1);
var p1hi = this.pg.first(cb1a, cb1b, pAbove); // gives the lower of the two
var p2hi = this.pg.first(cb2a, cb2b, pAbove);
var lnprp1 = this.pg.line(p1, p1hi);
var lnprp2 = this.pg.line(p2, p2hi);
var pSq1 = this.pg.first(lnprp1, c1, pAbove);
var pSq2 = this.pg.first(lnprp2, c2, pAbove);
var c1hi = this.pg.circle(pSq1, p1);
var c2hi = this.pg.circle(pSq2, p2);
var pMid1 = this.pg.first(c1,c1hi, p2);
var pMid2 = this.pg.first(c2,c2hi, p1);
var lnMid = this.pg.line(pMid1, pMid2);
var pgold1 = this.pg.first(lnMid, lnprp1, pAbove);
var pgold2 = this.pg.first(lnMid, lnprp2, pAbove);
var cgold1 = this.pg.circle(pgold2,p1);
var cgold2 = this.pg.circle(pgold1,p2);
var p3 = this.pg.first(cgold1, lnprp2, p2hi);
var p4 = this.pg.first(cgold2, lnprp1, p1hi);
var res = { "P1":p1, "P2":p2, "P3":p3, "P4":p4,
"L12":ln1, "L23":lnprp2, "L41":lnprp1, "C1":c1, "C2":c2, "PSQ1":pSq1, "PSQ2":pSq2 };
return res;
},
goldenOnLine2_test: function(t) {
var p0 = this.pg.given(0.33,0.33);
var p1 = this.pg.given(0.33,0.415);
var p2 = this.pg.given(0.33,0.5);
var p3 = this.pg.given(0.33,0.66);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.goldenOnLine2(pA, pB, pC);
var ln34 = this.pg.line(md.P3, md.P4);
// obligatory: YES, THIS IS GOLDEN
var md2 = this.goldenOnLine2(md.P4, md.PSQ1, md.P3);
},
// puts the long side on the line
// I don't have a direct construction for this
// but the gOL2 routine can be used; the gr's gnomon is a square
goldenOnLine3: function(p1,p2, pAbove) {
var gsh = this.goldenOnLine2(p1,p2,pAbove);
p3big = gsh.P3;
p4big = gsh.P4;
ln23 = gsh.L23;
ln41 = gsh.L41;
var c3 = this.pg.circle(p3big, p4big); // make a sq from the top two points of the larger GR
var c4 = this.pg.circle(p4big, p3big);
var p3 = this.pg.first(c4, ln41, p1);
var p4 = this.pg.first(c3, ln23, p1);
var res = { "P1":p1, "P2":p2, "P3":p3, "P4":p4,
"L12":gsh.L12, "L23":gsh.L23, "L41":gsh.L41, "C1":gsh.C1, "C2":gsh.C2 };
return res;
},
goldenOnLine3_test: function(t) {
var p0 = this.pg.given(0.33,0.33);
var p1 = this.pg.given(0.33,0.415);
var p2 = this.pg.given(0.33,0.5);
var p3 = this.pg.given(0.33,0.66);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.goldenOnLine3(pA, pB, pC);
var ln34 = this.pg.line(md.P3, md.P4);
},
/////////////////////// pentagons
/////////////////////// pentagons
/////////////////////// pentagons
pentagonInCircle: function(p0, p360, pAbove) {
var c0 = this.pg.circle(p0, p360);
var ln360 = this.pg.line(p0, p360);
var p180 = this.pg.second(c0, ln360, p360);
var c360_2 = this.pg.circle(p360, p180);
var c180_2 = this.pg.circle(p180, p360);
var p90_2 = this.pg.first(c360_2, c180_2, pAbove);
var p270_2 = this.pg.second(c360_2, c180_2, pAbove);
var equator = this.pg.line(p90_2, p270_2);
var p90 = this.pg.first(equator, c0, pAbove);
var c90 = this.pg.circle(p90, p0);
var pMidsHi = this.pg.first(c90,c0, pAbove);
var pMidsLo = this.pg.second(c90,c0, pAbove);
var lnMids = this.pg.line(pMidsHi, pMidsLo);
var pHalfRadius = this.pg.first(lnMids, equator, pAbove);
var cA = this.pg.circle(pHalfRadius, p360);
var pPent = this.pg.first(equator, cA, p0);
var cPent360 = this.pg.circle(p360, pPent);
var p72 = this.pg.first(c0, cPent360, pAbove);
var ser = this.series(5, p360, p72, c0);
var result = {
"P0":p360, "P1":p360, "P2":p72, "P3":ser["P3"], "P4":ser["P4"], "P5":ser["P5"],
"C0":cPent360, "C1":ser["C2"], "C2":ser["C3"], "C3":ser["C4"], "C4":ser["C5"],
};
return result;
},
pentagonInCircle_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.pentagonInCircle(pA,pB, pC);
var ln1 = this.pg.line(md.P1, md.P2);
var ln1 = this.pg.line(md.P2, md.P3);
var ln1 = this.pg.line(md.P3, md.P4);
var ln2 = this.pg.line(md.P4, md.P5);
var ln2 = this.pg.line(md.P5, md.P1);
},
// two points => pentagon using them as a side
pentagonOnLine: function(p1, p2, pAbove) {
var c1 = this.pg.circle(p1,p2);
var c2 = this.pg.circle(p2,p1);
var ln12 = this.pg.line(p1,p2);
// get midpt
var pHi = this.pg.first(c1,c2, pAbove);
var pLo = this.pg.second(c1,c2, pAbove);
var midLn = this.pg.line(pHi, pLo);
var center = this.pg.first(ln12, midLn, pAbove);
// get perp lines from p1, p2
var p0 = this.pg.second(c1, ln12, p2);
var p3 = this.pg.second(c2, ln12, p1);
var cP0 = this.pg.circle(p0,p2);
var cP1 = this.pg.circle(p1,p3);
var cP2 = this.pg.circle(p2,p0);
var cP3 = this.pg.circle(p3,p1);
var p1Hi = this.pg.first(cP0,cP2, pAbove);
var p2Hi = this.pg.first(cP1,cP3, pAbove);
var lnP1 = this.pg.line(p1, p1Hi);
var lnP2 = this.pg.line(p2, p2Hi);
// corners of square abve p1p2
var pSq1 = this.pg.first(lnP1, c1, pAbove);
var pSq2 = this.pg.first(lnP2, c2, pAbove);
// the meat!
var cPent = this.pg.circle(center, pSq1);
var pG = this.pg.first(cPent, ln12, p1);
var pH = this.pg.first(cPent, ln12, p2);
var cG = this.pg.circle(p1,pH);
var cH = this.pg.circle(p2,pG);
var pPent3 = this.pg.first(cG, c2, pAbove);
var pPent4 = this.pg.first(cG, cH, pAbove);
var pPent5 = this.pg.first(cH, c1, pAbove);
var res = { "P1":p1, "P2":p2, "P3":pPent3, "P4":pPent4, "P5":pPent5, "P0":center,
"Ln12":ln12, "LnMid":midLn, "CPent":cPent
};
return res;
},
pentagonOnLine_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.pentagonOnLine(pA, pB, pC);
var ln1 = this.pg.line(md.P1, md.P2);
var ln1 = this.pg.line(md.P2, md.P3);
var ln1 = this.pg.line(md.P3, md.P4);
var ln2 = this.pg.line(md.P4, md.P5);
var ln2 = this.pg.line(md.P5, md.P1);
},
// pentagon across line
// two points => pentagon using them as a side
pentagonAcrossLine: function(p1, p3, pAbove) {
var stl = this.sublimeTriangleFromLong(p1,p3,pAbove);
// "P1":p1, "P2":p2, "PG":pG, "CG":cRat,
// "PMid":midPt, "LMid":midLn, "CMid":cMid,
// "Perpendicular":perps.Perpendicular, "Connector":perps.Connector,
// "C1":c1, "C2":perps.C1, "Hypotenuse":hyp
var c5 = this.pg.circle(stl.P3, p1);
var pbis = this.pg.first(c5, stl.CG, p3);
var bLn = this.pg.line(p3, pbis);
var p0 = this.pg.first(stl.LMid, bLn, pAbove);
var c0 = this.pg.circle(p0, p1);
var p2 = this.pg.first(stl.LMid,c0, stl.PMid);
var p4 = this.pg.second(c0, c5, p1);
stl["P5"] = stl.P3;
stl["P4"] = p4;
stl["P3"] = p3;
stl["P2"] = p2;
stl["P2"] = p2;
stl["P0"] = p0;
stl["C0"] = c0; // complex; many different circles available.
return stl;
},
pentagonAcrossLine_test: function(t) {
// var pA = this.pg.given(0.5,0.5);
// var pB = this.pg.given(0.5,0.2);
// var pC = this.pg.given(0.9,0.1);
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.43);
var p2 = this.pg.given(0.5,0.36);
var p3 = this.pg.given(0.5,0.07);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);
var c3 = this.pg.circle(p0,p3);
var pA = this.pg.addParametricPoint(c1, t);
var pB = this.pg.addParametricPoint(c2, t*1.1);
var pC = this.pg.addParametricPoint(c3, t*.9+.5);
var md = this.pentagonAcrossLine(pA,pB,pC);
},
/////////////////////// hexagons
/////////////////////// hexagons
/////////////////////// hexagons
// and 6 points on C1, from which a regular hexagon may be inscribed,
// Clockwise vs counterclockwise: C2 will be closer to pAbove, and the last c, farther away
hexagonInCircle: function(p0, p12,pAbove) {
var c0 = this.pg.circle(p0, p12);
var c12 = this.pg.circle(p12, p0); // named for place on clock face
var p2 = this.pg.first(c0, c12, pAbove);
var ser = this.series(6, p12,p2, c0);
var result = {
"P1":p12, "P2":p2, "P3":ser.P3, "P4":ser.P4, "P5":ser.P5, "P0":p0,
"C1":c12, "C2":ser.C2, "C3":ser.C3, "C4":ser.C4, "C5":ser.C5, "C6":ser.C6,
};
return result;
},
hexagonInCircle_test: function(t) {
var p0 = this.pg.given(0.5,0.5);
var p1 = this.pg.given(0.5,0.4);
var p2 = this.pg.given(0.5,0.3);
var p3 = this.pg.given(0.5,0.1);
var c1 = this.pg.circle(p0,p1);
var c2 = this.pg.circle(p0,p2);