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 package net.sourceforge.kamiwaai.geometricalgebra;
42 import java.awt.BasicStroke;
43 import java.awt.Color;
44 import java.awt.Graphics;
45 import java.awt.Graphics2D;
46 import java.awt.geom.GeneralPath;
47 public class Circle extends GeometricObject{
48
49
50 private Color color = Color.red;
51 public Circle(MultiVector L3) {
52 L = L3;
53 }
54 public Circle(PointC point1, PointC point2, PointC point3) {
55 L = point1.getMultiVector().OutProd(point2.getMultiVector())
56 .OutProd(point3.getMultiVector());
57 }
58 public double radius() {
59 double r2 = (L.ScProd(L))
60 * (-1.0 / (n.OutProd(L).ScProd(n.OutProd(L))));
61 double r = Math.sqrt(r2);
62 return r;
63 }
64 public MultiVector Center() {
65
66 Circle LC = new Circle(L);
67 MultiVector low = n.OutProd(L).mult(I).multSc(-1.0);
68 double llow = low.ScProd(low);
69 MultiVector Low = low.multSc(1.0 / llow);
70 MultiVector Result = L.mult(I).mult(Low);
71 double r = LC.radius();
72 MultiVector Cent = Result.add(n.multSc(0.5 * r * r));
73 return Cent;
74 }
75
76 public double[] center() {
77
78 double[] cvector = new double[3];
79 Circle LC = new Circle(L);
80 cvector[0] = LC.Center().get3DEuclidianPoint()[0];
81 cvector[1] = LC.Center().get3DEuclidianPoint()[1];
82 cvector[2] = LC.Center().get3DEuclidianPoint()[2];
83 return cvector;
84 }
85 public MultiVector Cplane() {
86
87
88 MultiVector ICp = L.OutProd(n).Rcontract(N);
89 MultiVector IC = ICp.normalize();
90 return IC;
91 }
92 public MultiVector generator(int inc) {
93
94
95 int UP = inc;
96 double angle = 2 * Math.PI / UP;
97 MultiVector cv, IC, Tc, Tcr, R, D;
98 Circle LC = new Circle(L);
99 cv = LC.Center().OutProd(N).mult(N);
100
101 Tc = One.add(n.mult(cv).multSc(0.5));
102 Tcr = Tc.reverse();
103 IC = LC.Cplane();
104
105 R = One.multSc(Math.cos(0.5 * angle)).add(
106 IC.multSc(Math.sin(0.5 * angle)));
107
108 D = Tc.mult(R).mult(Tcr);
109 return D;
110 }
111 public MultiVector PonC() {
112
113 MultiVector IC, rv, rad, Trad, Tradr, ponc;
114 double r;
115 Circle LC = new Circle(L);
116 IC = LC.Cplane();
117 rv = e1.Lcontract(IC).add(e2.Lcontract(IC));
118 r = LC.radius();
119 rad = rv.multSc(r / (rv.magnitude()));
120
121 Trad = One.add(n.mult(rad).multSc(0.5));
122 Tradr = Trad.reverse();
123 ponc = Trad.mult(LC.Center()).mult(Tradr);
124 return ponc;
125 }
126 public double[][] cpoints(int inc) {
127
128 double[][] points = new double[inc][3];
129 MultiVector D, Dr, Cpoint;
130 int f, num;
131 Circle LC = new Circle(L);
132 num = inc;
133 D = LC.generator(num);
134 Dr = D.reverse();
135 Cpoint = LC.PonC();
136 points[0][0] = Cpoint.get3DEuclidianPoint()[0];
137 points[0][1] = Cpoint.get3DEuclidianPoint()[1];
138 points[0][2] = Cpoint.get3DEuclidianPoint()[2];
139 for (f = 1; f < num; f++) {
140 Cpoint = D.mult(Cpoint).mult(Dr);
141
142 points[f][0] = Cpoint.get3DEuclidianPoint()[0];
143 points[f][1] = Cpoint.get3DEuclidianPoint()[1];
144 points[f][2] = Cpoint.get3DEuclidianPoint()[2];
145 }
146 return points;
147 }
148 public void setColor(Color c) {
149 color = c;
150 }
151 public void draw(Graphics g) {
152 int nump = 500;
153 double[][] CPs;
154 CPs = cpoints(nump);
155 Graphics2D g2 = (Graphics2D) g;
156 g2.setColor(color);
157 g2.setStroke(new BasicStroke(1.0f));
158
159 GeneralPath p = new GeneralPath();
160 p.moveTo((float) CPs[0][0], (float) CPs[0][1]);
161 for (int m = 1; m < nump; m++) {
162 p.lineTo((float) CPs[m][0], (float) CPs[m][1]);
163 }
164 p.closePath();
165
166 g2.draw(p);
167 }
168 public void drawZ(Graphics g) {
169 int nump = 60;
170 double[][] CPs;
171 CPs = cpoints(nump);
172 Graphics2D g2 = (Graphics2D) g;
173 g2.setColor(color);
174 g2.setStroke(new BasicStroke(1.0f));
175
176 GeneralPath p = new GeneralPath();
177 p.moveTo((float) CPs[0][2], (float) CPs[0][1]);
178 for (int m = 1; m < nump; m++) {
179 p.lineTo((float) CPs[m][2], (float) CPs[m][1]);
180 }
181 p.closePath();
182
183 g2.draw(p);
184 }
185
186 }