summaryrefslogtreecommitdiffstats
path: root/qtsharp/src/examples/samples/quantumfractals.cs
blob: fe6c914e7f8e31ccc2eea48c949284197d746ad1 (plain)
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
// quantumfractals.cs - Port of eeqt to Qt#
// Author: Adam Treat <[email protected]>
// (c) 2002 Adam Treat
// Licensed under the terms of the GNU GPL

namespace Qf {

	using Qt;
	using System;
	using System.Threading;
	
	public class FractalViewer : TQMainWindow {
		
		//Menuing
		private TQMenuBar menubar;
		private TQPopupMenu filemenu;
		private TQPopupMenu shapemenu;
		private TQPopupMenu settingsmenu;
		
		public static int Main (string[] args)
		{
			//Initialize and start the main event loop
			TQApplication app = new TQApplication (args);
			FractalViewer view = new FractalViewer ();
			app.SetMainWidget (view);
			view.Show ();
			return app.Exec ();
		}
		
		public FractalViewer (): base (null, "main")
		{	
			SetCaption ("Quantum Fractals");
			
			//Setup the display
			Display display = new Display (this);
			SetCentralWidget (display);
			
			//Setup the filemenu
			filemenu = new TQPopupMenu (null, "filemenu");
			filemenu.InsertItem ("&Screenshot", display, TQT_SLOT ("SlotScreenshot()"));
			filemenu.InsertSeparator ();
			filemenu.InsertItem ("&Quit", qApp, TQT_SLOT ("quit()"));
			
			//Setup the shapemenu
			shapemenu = new TQPopupMenu (null, "typemenu");
			shapemenu.InsertItem( "&Tetrahedron", 0);
			shapemenu.InsertItem( "&Cube", 1);
			shapemenu.InsertItem( "&Octahedron", 2);
			shapemenu.InsertItem( "&Icosahedron", 3);
			shapemenu.InsertItem( "&Dodecahedron", 4);
			shapemenu.InsertItem( "&Double Tetrahedron", 5);
			shapemenu.InsertItem( "&Icosidodecahedron", 6);
			
			//Connect the shapemenu
			TQObject.Connect (shapemenu, TQT_SIGNAL ("activated(int)"),
				display, TQT_SLOT("SlotShapeMenu(int)"));
			
			//Setup the settingsmenu
			settingsmenu = new TQPopupMenu (null, "settingsmenu");
			settingsmenu.InsertItem ("&Alpha", display, TQT_SLOT ("SlotSetAlpha()"));
			
			//Setup the menubar
			menubar = new TQMenuBar (this, "");
			menubar.InsertItem ("&File", filemenu);
			menubar.InsertItem ("&Shape", shapemenu);
			menubar.InsertItem ("&Settings", settingsmenu);
		}
	}
	
	public class Display: TQWidget, IQuantumFractal {
		
		//Labels
		TQLabel count;
		TQLabel shape;
		TQLabel alpha;
		
		//Buttons
		TQPushButton start;
		TQPushButton stop;
		TQPushButton reset;
		TQPushButton gray;
		TQPushButton intense;
		
		//Drawable region
		QPaintBuffer buffer;
		
		//Layouts
		TQVBoxLayout layout;
		TQHBoxLayout buttons;
		TQVBoxLayout labels;
		
		//Engine controller variables
   		int[] topDensity = new int[0];
   		int[] bottomDensity = new int[0];
		int resolution = 400;
		int scale = 1;
   		double centerX = 0;
   		double centerY = 0;
		int i = 0;
		bool Grayscale = true;
		bool Intense = false;
		bool Running = false;
		bool WasRunning = false;
		
		//The engine
		QuantumFractals qf;
		Thread engine;
		
		public Display (TQWidget parent): base (parent)
		{
			//Setup the sizes
			TQSize size = new TQSize (resolution, resolution);
			parent.SetBaseSize (size);
			
			//Some nice colors
			SetPaletteBackgroundColor (new TQColor ("Black"));
			SetPaletteForegroundColor (new TQColor ("LightBlue"));
			
			//Setup the buttons
			start = new TQPushButton ("Start", this);
			stop = new TQPushButton ("Stop", this);
			reset = new TQPushButton ("Reset", this);
			gray = new TQPushButton ("Color", this);
			intense = new TQPushButton ("Intensity", this);
			
			//Setup the labels
			count = new TQLabel (this);
			alpha = new TQLabel (this);
			shape = new TQLabel (this);
			
			//Setup the drawable
			buffer = new QPaintBuffer (this);
			buffer.SetMinimumSize (size);
			
			//Create the layouts
			layout = new TQVBoxLayout (this);
			buttons = new TQHBoxLayout (layout);
			
			//Add some buttons
			buttons.AddWidget (start);
			buttons.AddWidget (stop);
			buttons.AddWidget (reset);
			buttons.AddWidget (gray);
			buttons.AddWidget (intense);
			
			//Connect the buttons and SlotQuit
			TQObject.Connect (start, TQT_SIGNAL ("clicked()"),
				this, TQT_SLOT ("SlotStart()"));
			TQObject.Connect (stop, TQT_SIGNAL ("clicked()"),
				this, TQT_SLOT ("SlotStop()"));
			TQObject.Connect (reset, TQT_SIGNAL ("clicked()"),
				this, TQT_SLOT ("SlotReset()"));
			TQObject.Connect (gray, TQT_SIGNAL ("clicked()"),
				this, TQT_SLOT ("SlotGray()"));
			TQObject.Connect (intense, TQT_SIGNAL ("clicked()"),
				this, TQT_SLOT ("SlotIntense()"));
			TQObject.Connect (buffer, TQT_SIGNAL ("Painted()"),
				this, TQT_SLOT ("SlotSetLabels()"));
			TQObject.Connect (qApp, TQT_SIGNAL ("lastWindowClosed ()"),
				this, TQT_SLOT ("SlotQuit ()"));
			
			//Layout labels
			labels = new TQVBoxLayout (layout);
			labels.AddWidget (count);
			labels.AddWidget (shape);
			labels.AddWidget (alpha);
			
			//Layout buffer
			layout.AddWidget (buffer, 1);
			
			//Finally create the data engine
			qf = new QuantumFractals (this);
			
			//Handle resize events
			resizeEvent += new ResizeEvent (TouchResize);
		}
		
		//This is where the controller receives data from the engine
		public void UpdateData (double[] d)
		{
			i++; //Keep track of the number of points
			
			//Set the density arrays to match the resolution
			if (resolution * resolution != topDensity.Length) {
				topDensity = new int[resolution * resolution];
				bottomDensity = new int[resolution * resolution];
			}
			
			//setup the sphere
			int res = resolution;
			int res2 = res / 2;
			int x = res / 2 + (int)(res2 * scale * (d[0] - centerX));
			int y = res / 2 + (int)(res2 * scale * (d[1] - centerY));
			double z = d[2];
			
			if ((x < res) && (x >= 0) && (y >= 0) && (y < res)) {
			
				if (z >= 0)
					topDensity[y * resolution + x]++;
				else
					bottomDensity[y * resolution + x]++;
					
			}
			
			//Convert the density into a color
			int top = topDensity[y * resolution + x];
			//int bot = bottomDensity[y * resolution + x];
			top = Math.Min (top, 255);
			//bot = Math.Min (bot, 255);
			
			//Log color system not working well :(
			if (Intense) {
				top = (int)(Math.Log (top + 1));
				//bot = (int)(Math.Log (bot + 1));
			}
			
			int topdepth = RGB (top,top,top);
			//int botdepth = RGB (bot,bot,bot);
			
			//Finally draw the pixel
			SetPixel (x, y, topdepth);
			//SetPixel (x, y, botdepth);
		}
		
		//Calls the drawable
		public void SetPixel (int x, int y, int depth)
		{
			buffer.PaintPixel (x, y, depth);
		}
		
		//Convert the color into a depth
		public int RGB (int r, int g, int b)
		{
			if (!Grayscale) {
				
				r = Intensity (r < 128 ? 128 - r : 0);
				g = Intensity (128 - Math.Abs (g - 128));
				b = Intensity (b < 128 ? 0 : b - 128);
			
			} else {
			
				r = Intensity (r);
				g = Intensity (g);
				b = Intensity (b);
				
			}
	       		//Console.WriteLine ("{0} {1} {2}", r,g,b);
			return 256 * 256 * r + 256 * g + b;
		}
		
		//This provides more detail
		private int Intensity(int val)
		{
			int ret;
			
			double bases = 64;
			double scale = 256.0 / (256.0 - bases);
			ret = (int)(bases + ((double)val) / scale);
			
			//if gray then black, if color then white
			if (val == 0 && Grayscale)
				ret = 0;
			else if (val == 0)
				ret = 255;
			return ret;
		}
		
		//Draw the labels
		private void SlotSetLabels ()
		{
			count.SetText ("Count: " + i.ToString ());
			shape.SetText ("Shape: " + qf.GetPolytope ());
			alpha.SetText ("Alpha: " + qf.Alpha.ToString ());
		}
		
		//Start the engine
		private void SlotStart ()
		{
			engine = new Thread(new ThreadStart(qf.Start));
			engine.Start ();
			Running = true;
		}
		
		//Stop the engine
		private void SlotStop ()
		{
			if (engine != null)
				if (engine.IsAlive)
					engine.Abort ();
			Running = false;
		}
		
		//Reset everything
		private void SlotReset ()
		{
			SlotStop ();
			ResetBuffer ();
			SlotStart ();
		}
		
		//Reset the drawable
		private void ResetBuffer ()
		{
			i = 0;
			SlotSetLabels ();
			topDensity = new int[0];
   			bottomDensity = new int[0];
			buffer.Reset ();
		}
		
		//Toggles the color scheme
		private void SlotGray ()
		{
			Grayscale = !Grayscale;
		}
		
		//Toggles log color scheme
		//Not working so well :(
		private void SlotIntense ()
		{
			Intense = !Intense;
		}
		
		//Change the platonic shape
		private void SlotShapeMenu (int item)
		{
			WasRunning = Running ? true : false;
				
			SlotStop ();
			ResetBuffer ();
			
			switch(item) {
			
				case 0:
					qf.SetPolytope (0);
					break;
				case 1:
					qf.SetPolytope (1);
					break;
				case 2:
					qf.SetPolytope (2);
					break;
				case 3:
					qf.SetPolytope (3);
					break;
				case 4:
					qf.SetPolytope (4);
					break;
				case 5:
					qf.SetPolytope (5);
					break;
				case 6:
					qf.SetPolytope (6);
					break;
				Default:
					qf.SetPolytope (0);
					break;
			}
			
			if (WasRunning)
				SlotStart ();
		}
		
		//Save the drawable as a screenshot
		private void SlotScreenshot ()
		{
			WasRunning = Running ? true : false;
			
			SlotStop ();
			string filename = TQFileDialog.GetSaveFileName (
				
				TQDir.HomeDirPath (), "*", this, "save",
				"Save Screenshot", "*.png", true
			);

                        if (filename != null)
				buffer.Save (filename);
			
			if (WasRunning)
				SlotStart ();
		}
		
		//Set the alpha engine variable
		private void SlotSetAlpha ()
		{
			WasRunning = Running ? true : false;
			
			SlotStop ();
			qf.Alpha = QInputDialog.GetDouble (
            		
				"Set Alpha", "Alpha: ", qf.Alpha, 0, 2, 32
	    		);
			
			if (WasRunning) 
				SlotStart ();
			else
				SlotSetLabels ();
		}
		
		//Make sure to quit all threads upon exit
		private void SlotQuit ()
		{
			SlotStop ();
			buffer.Stop ();
		}
		
		//Need to reset the resolution upon resize
		private void TouchResize (TQResizeEvent e)
		{
			int height = buffer.Size ().Height ();
			int width = buffer.Size ().Width ();
			
			resolution = height > width ? width : height;
		}
	}

	[DeclareQtSignal ("Painted()")]
	public class QPaintBuffer : TQFrame {
		
		//Drawables
		private TQPixmap buffer;
		private TQImage image;
		
		//Timer
		private TimerCallback call;
		private Timer timer;

		public QPaintBuffer (TQWidget parent) : base (parent)
		{
			SetBackgroundMode (Qt.BackgroundMode.NoBackground);
			
			//Create drawables
			buffer = new TQPixmap ();
			image = new TQImage (Size (), 32);
			
			//Setup the event handlers
			paintEvent += new PaintEvent (TouchPaint);
			resizeEvent += new ResizeEvent (TouchResize);
			focusInEvent += new FocusInEvent (TouchFocus);
			focusOutEvent += new FocusOutEvent (TouchFocus);
			
			//Start the timer
			call = new TimerCallback(PaintImage);
			timer = new Timer(call, null, 1000, 1000);
			
		}
		
		//Resets the drawables
		public void Reset ()
		{
			buffer = new TQPixmap ();
			image = new TQImage (Size (), 32);
			PaintImage (null);
		}
		
		//Paints a pixel to the image
		public void PaintPixel (int x, int y, int depth)
		{
			lock (this) {
				if (x < image.Width () && y < image.Height ())
					image.SetPixel (x, y, (uint)depth);
			}
		}
		
		//Saves the image to a file
		public void Save (string filename)
		{
			image.Save (filename, "PNG");
		}
		
		//Paints the image to the screen and emits Painted
		private void PaintImage (object state)
		{
			buffer.ConvertFromImage (image);
			PerformPaint ();
			Emit ("Painted()");
		}
		
		//The actual bitblt to the screen
		private void PerformPaint ()
		{
			BitBlt(this, 0, 0, buffer,
				0, 0, -1, -1, RasterOp.CopyROP, false);
		}
		
		//Receive focus events
		private void TouchFocus (TQFocusEvent e)
		{
			PerformPaint ();
		}
			
		//Receive paint events
		private void TouchPaint (TQPaintEvent e)
		{	
			PerformPaint (); 
		}
		
		//Receive resize events
		private void TouchResize (TQResizeEvent e)
		{
			image = new TQImage (e.Size (), 32);
			buffer.Resize (e.Size());
			buffer.Fill (new TQColor("black"));
			BitBlt (buffer, 0, 0, new TQPixmap (buffer),
				0, 0, -1, -1, RasterOp.CopyROP, false);
		}
		
		//Dispose of the timer
		public void Stop ()
		{
			timer.Dispose ();
		}
	}

	public interface IQuantumFractal {
	
		void UpdateData (Double [] data);
	}
	
	//Polytope types
	public enum Shapes {
		TETRAHEDRON = 0,
		CUBE = 1,
		OCTAHEDRON = 2,
		ICOSAHEDRON = 3,
		DODECAHEDRON = 4,
		DOUBLE_TETRAHEDRON = 5,
		ICOSIDODECAHEDRON = 6
	}
	
	public class QuantumFractals {
		
		private int t = 0;
		private double[] p; //Detector probabilities
		private double[] fp; //Fractal point
		private double[][] n; //Detector points
		private double[] counter; //Detect counter
		private double alpha = 0.61803398874989288039384209090709; //Initialize to 1/phi
		
		private Random random;
		private Shapes polytope;
		private IQuantumFractal consumer;
		
		public QuantumFractals (IQuantumFractal consumer)
   		{
			this.consumer = consumer;
			SetPolytope (0);
			Init ();
		}
		
		public double Alpha
		{
			get { return alpha; }
			set { alpha = value; }
		}

		private void Init ()
		{
			random = new Random ();
			
			//Default values
			t = 0;

			counter = new double[n.Length]; //Detect counter
			fp = new double[3]; //Fractal point
			p = new double[n.Length];

			//Initial state
			fp[0] = random.NextDouble () -0.5;
			fp[1] = random.NextDouble () -0.5;
			fp[2] = random.NextDouble () -0.5;
			
			double sum = Math.Sqrt (Product (fp, fp));
			
			fp[0] = fp[0] / sum;
			fp[1] = fp[1] / sum;
			fp[2] = fp[2] / sum;
		}
		
		//Main fractal generator loop
		public void Start ()
		{
			Init ();

			//double n1 = (1.0) / n.Length as double;
			double n1 = (1.0) / n.Length;
			
			double alpha12 = 2 * alpha / (n.Length * (1 + alpha * alpha));

			do {
				//Increase t
				t++;

				//Calculate detector click probabilities
				for (int i = 0; i < p.Length; i++)
					p[i] = n1 + alpha12 * Product (n[i], fp);
				
				//Get next random number
				double r = random.NextDouble ();

				//Check which detector that clicked
				double ptmp = 0;
				double[] detector = null;
				
				for (int i = 0; i < p.Length; i++) {
				
					ptmp += p[i];

					if (r <= ptmp) {
						//We found which detector clicked
						detector = n[i];
						counter[i]++;
						break;
					}
				}

				if (detector == null)
					detector = n[p.Length - 1];

				//Project
				double sc = Product (fp, detector);

				for (int j = 0; j < 3; j++)
					fp[j]= (1 - alpha * alpha) * fp[j] + 2 * alpha * (1 + alpha * sc) * detector[j];

				//Normalize
				double norm = Math.Sqrt (Product (fp, fp));
				
				for (int j=0; j<3; j++)
					fp[j] /= norm;

				consumer.UpdateData (fp);
					
			} while (true);
		}
		
		
		//Calculate the scalar product of two vectors
		private double Product (double[] v1, double[] v2)
		{
			double sc = 0;
      			for(int i=0; i < v1.Length; i++)
				sc += v1[i] * v2[i];
			return sc;
		}
		
		public string GetPolytope ()
		{
			string ret = String.Empty;
			switch (polytope) {
				case Shapes.TETRAHEDRON:
					ret = "Tetrahedron";
					break;
				case Shapes.CUBE:
					ret = "Cube";
					break;
				case Shapes.OCTAHEDRON:
					ret = "Octahedron";
					break;
				case Shapes.ICOSAHEDRON:
					ret = "Icosahedron";
					break;
				case Shapes.DODECAHEDRON:
					ret = "Dodecahedron";
					break;
				case Shapes.DOUBLE_TETRAHEDRON:
					ret = "Double Tetrahedron";
					break;
				case Shapes.ICOSIDODECAHEDRON:
					ret = "Icosidodecahedron";
					break;
				Default:
					ret = "Unknown";
					break;
			}
			return ret;
		}
		
		public void SetPolytope (int type)
		{		
			polytope = (Qf.Shapes)type;
			
			switch (type) {
			
				case 0: {
				
					n = new double[4][];
					n[0] =	new double[] {0,0,1.0};
					n[1] =	new double[] {0.9428090415820634,0,-0.3333333333333333};
					n[2] =	new double[] {-0.4714045207910317,0.816496580927726,-0.3333333333333333};
					n[3] =	new double[] {-0.4714045207910317, -0.816496580927726, -0.3333333333333333};

					break;
				}

				case 1: {
				
					n = new double[8][];
					n[0] =	new double[] {0, 0, 1.0};
					n[1] =	new double[] {0.9428090415820634, 0, 0.3333333333333333};
					n[2] =	new double[] {-0.4714045207910317, 0.816496580927726, 0.3333333333333333};
					n[3] =	new double[] {-0.4714045207910317, -0.816496580927726, 0.3333333333333333};
					n[4] =	new double[] {0.4714045207910317, 0.816496580927726, -0.3333333333333333};
					n[5] =	new double[] {0.4714045207910317, -0.816496580927726, -0.3333333333333333};
					n[6] =	new double[] {-0.9428090415820634, 0, -0.3333333333333333};
					n[7] =	new double[] {0, 0, -1.0};
					break;
				}

				case 2: {
				
					n = new double[6][];
					n[0] =	new double[] {0, 0, 1.0};
					n[1] =	new double[] {1.0, 0, 0};
					n[2] =	new double[] {0, 1.0, 0};
					n[3] =	new double[] {-1.0, 0, 0};
					n[4] =	new double[] {0, -1.0, 0};
					n[5] =	new double[] {0, 0, -1.0};

					break;
				}

				case 3: {
				
					n = new double[12][];
					n[0] =	new double[] {0, 0, 1.0};
					n[1] =	new double[] {0.8944271909999159, 0, 0.4472135954999579};
					n[2] =	new double[] {0.276393202250021, 0.85065080835204, 0.4472135954999579};
					n[3] =	new double[] {-0.723606797749979, 0.5257311121191336, 0.4472135954999579};
					n[4] =	new double[] {-0.723606797749979, -0.5257311121191336, 0.4472135954999579};
					n[5] =	new double[] {0.276393202250021, -0.85065080835204, 0.4472135954999579};
					n[6] =	new double[] {0.723606797749979, 0.5257311121191336, -0.4472135954999579};
					n[7] =	new double[] {0.723606797749979, -0.5257311121191336, -0.4472135954999579};
					n[8] =	new double[] {-0.276393202250021, 0.85065080835204, -0.4472135954999579};
					n[9] =	new double[] {-0.8944271909999159, 0, -0.4472135954999579};
					n[10] =	new double[] {-0.276393202250021, -0.85065080835204, -0.4472135954999579};
					n[11] =	new double[] {0, 0, -1.0};

					break;
				}

				case 4: {
				
					n = new double[20][];
					n[0] =	new double[] {0, 0, 1.0};
					n[1] =	new double[] {0.6666666666666666, 0, 0.7453559924999299};
					n[2] =	new double[] {-0.3333333333333333, 0.5773502691896257, 0.7453559924999299};
					n[3] =	new double[] {-0.3333333333333333, -0.5773502691896257, 0.7453559924999299};
					n[4] =	new double[] {0.7453559924999299, 0.5773502691896257, 0.3333333333333333};
					n[5] =	new double[] {0.7453559924999299, -0.5773502691896257, 0.3333333333333333};
					n[6] =	new double[] {-0.8726779962499649, 0.35682208977308993, 0.3333333333333333};
					n[7] =	new double[] {0.12732200375003502, 0.9341723589627157, 0.3333333333333333};
					n[8] =	new double[] {0.12732200375003502, -0.9341723589627157, 0.3333333333333333};
					n[9] =	new double[] {-0.8726779962499649, -0.35682208977308993, 0.3333333333333333};
					n[10] =	new double[] {0.8726779962499649, 0.35682208977308993, -0.3333333333333333};
					n[11] =	new double[] {0.8726779962499649, -0.35682208977308993, -0.3333333333333333};
					n[12] =	new double[] {-0.7453559924999299, 0.5773502691896257, -0.3333333333333333};
					n[13] =	new double[] {-0.12732200375003502, 0.9341723589627157, -0.3333333333333333};
					n[14] =	new double[] {-0.12732200375003502, -0.9341723589627157, -0.3333333333333333};
					n[15] =	new double[] {-0.7453559924999299, -0.5773502691896257, -0.3333333333333333};
					n[16] =	new double[] {0.3333333333333333, 0.5773502691896257, -0.7453559924999299};
					n[17] =	new double[] {0.3333333333333333, -0.5773502691896257, -0.7453559924999299};
					n[18] =	new double[] {-0.6666666666666666, 0, -0.7453559924999299};
					n[19] =	new double[] {0, 0, -1.0};
					break;
				}

				case 5: {
				
					n = new double[8][];
					n[0] =	new double[] {0,0,1.0};
					n[1] =	new double[] {0.9428090415820634,0,-0.3333333333333333};
					n[2] =	new double[] {-0.4714045207910317,0.816496580927726,-0.3333333333333333};
					n[3] =	new double[] {-0.4714045207910317, -0.816496580927726, -0.3333333333333333};
					n[4] =	new double[] {0,0,-1.0};
					n[5] =	new double[] {-0.9428090415820634,0,0.3333333333333333};
					n[6] =	new double[] {0.4714045207910317,-0.816496580927726,0.3333333333333333};
					n[7] =	new double[] {0.4714045207910317, 0.816496580927726, 0.3333333333333333};

					break;
				}

				case 6: {
				
					double u=0.5;
					double v=0.8090169943749475; // (1/2)*phi
					double w=0.3090169943749474; // (1/2)/phi

					n = new double[30][];
					n[0] =	new double[] {1,0,0};
					n[1] =	new double[] {-1,0,0};
					n[2] =	new double[] {0,1,0};
					n[3] =	new double[] {0,-1,0};
					n[4] =	new double[] {0,0,1};
					n[5] =	new double[] {0,0,-1};
					n[6] =	new double[] {u,v,w};
					n[7] =	new double[] {-u,v,w};
					n[8] =	new double[] {u,-v,w};
					n[9] =	new double[] {u,v,-w};
					n[10] =	new double[] {-u,-v,w};
					n[11] =	new double[] {u,-v,-w};
					n[12] =	new double[] {-u,v,-w};
					n[13] =	new double[] {-u,-v,-w};
					n[14] =	new double[] {v,w,u};
					n[15] =	new double[] {v,w,-u};
					n[16] =	new double[] {-v,w,u};
					n[17] =	new double[] {v,-w,u};
					n[18] =	new double[] {-v,w,-u};
					n[19] =	new double[] {-v,-w,u};
					n[20] =	new double[] {v,-w,-u};
					n[21] =	new double[] {-v,-w,-u};
					n[22] =	new double[] {w,u,v};
					n[23] =	new double[] {w,-u,v};
					n[24] =	new double[] {w,u,-v};
					n[25] =	new double[] {-w,u,v};
					n[26] =	new double[] {w,-u,-v};
					n[27] =	new double[] {-w,u,-v};
					n[28] =	new double[] {-w,-u,v};
					n[29] =	new double[] {-w,-u,-v};
					break;
				}

				Default:
					break;
			}
		}
	}
}