View Javadoc

1   // GeometricAlgebra Java package file
2   // Current version
3   // Go to ... http://sinai.mech.fukui-u.ac.jp/gcj/software/KamiWaAi/index.html
4   // Copyright (C) 2003, Eckhard M.S. Hitzer
5   //
6   // This library is free software; you can redistribute it and/or
7   // modify it under the terms of the GNU Lesser General Public
8   // License as published by the Free Software Foundation; either
9   // version 2.1 of the License, or any later version.
10  //
11  // This library is distributed in the hope that it will be useful,
12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  // Lesser General Public License for more details.
15  //
16  // You should have received a copy of the GNU Lesser General Public
17  // License along with this library; if not, write to the Free Software
18  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  // Go to ... http://www.gnu.org/copyleft/lesser.html
20  // 
21  // hitzer@mech.fukui-u.ac.jp
22  // 
23  // Department of Mechanical Engineering, Fukui University
24  // 3-9-1 Bunkyo, 910-8507 Fukui, Japan
25  // 
26  //
27  //
28  // It the personal wish of E.M.S. Hitzer,
29  // that you never use this software for infringing human dignity:
30  //
31  // "God created man in his own image,
32  // in the image of God he created him;
33  // male and female he created them.
34  // [The Bible, Genesis chapter 1 verse 27]
35  //
36  //
37  //
38  // 
39  // File PointC.java
40  // 2003-3-4
41  //
42  // 
43  //
44  
45  package net.sourceforge.kamiwaai.geometricalgebra;
46  
47  import java.awt.Color;
48  import java.awt.Graphics;
49  import java.awt.Graphics2D;
50  import java.awt.geom.Ellipse2D;
51  
52  public class PointC extends GeometricObject {
53  	// The default color of points will be blue in the front view
54  	// and green in the right side view.
55  	private Color color = Color.blue;
56  
57  	private Color rightcolor = Color.green;
58  
59  	private int pointsize = 10;
60  
61  	public PointC() {
62  		L = nbar; // This sets the point at the origin.
63  	}
64  
65  	public PointC(double e1c, double e2c, double e3c) {
66  		L = nbar;
67  		//    	MultiVector Tc1, Tc2, Tc3, Tcr1, Tcr2, Tcr3;
68  		//		Tc1 = One.add(n.mult(e1.multSc(e1c - L.ScProd(e1))).multSc(0.5));
69  		//		Tcr1 = Tc1.reverse();
70  		//		Tc2 = One.add(n.mult(e2.multSc(e2c - L.ScProd(e2))).multSc(0.5));
71  		//		Tcr2 = Tc2.reverse();
72  		//		Tc3 = One.add(n.mult(e3.multSc(e3c - L.ScProd(e3))).multSc(0.5));
73  		//		Tcr3 = Tc3.reverse();
74  		//		L = Tc1.mult(Tc2).mult(Tc3).mult(L).mult(Tcr3).mult(Tcr2).mult(Tcr1);
75  		MultiVector Tc = One.add(n.mult(e1.multSc(e1c - L.ScProd(e1))).multSc(0.5)).add(
76  				n.mult(e2.multSc(e2c - L.ScProd(e2))).multSc(0.5)).add(
77  				n.mult(e3.multSc(e3c - L.ScProd(e3))).multSc(0.5));
78  		L = Tc.mult(L).mult(Tc.reverse());
79  	}
80  
81  	public PointC(MultiVector L1) {
82  		L = L1;
83  	}
84  
85  	public void sete1(double e1c) {
86  		MultiVector Tc, Tcr;
87  		Tc = One.add(n.mult(e1.multSc(e1c - L.ScProd(e1))).multSc(0.5));
88  		Tcr = Tc.reverse();
89  		L = Tc.mult(L).mult(Tcr);
90  	}
91  
92  	public void sete2(double e2c) {
93  		MultiVector Tc, Tcr;
94  		Tc = One.add(n.mult(e2.multSc(e2c - L.ScProd(e2))).multSc(0.5));
95  		Tcr = Tc.reverse();
96  		L = Tc.mult(L).mult(Tcr);
97  	}
98  
99  	public void sete3(double e3c) {
100 		MultiVector Tc, Tcr;
101 		Tc = One.add(n.mult(e3.multSc(e3c - L.ScProd(e3))).multSc(0.5));
102 		Tcr = Tc.reverse();
103 		L = Tc.mult(L).mult(Tcr);
104 	}
105 
106 	public void setColor(Color c) {
107 		color = c;
108 	}
109 
110 	public void setRightColor(Color rc) {
111 		rightcolor = rc;
112 	}
113 
114 	public void setSize(int s) {
115 		pointsize = s;
116 	}
117 
118 	double[] coord() {
119 		double[] lps = new double[3];
120 		lps[0] = L.ScProd(e1);
121 		lps[1] = L.ScProd(e2);
122 		lps[2] = L.ScProd(e3);
123 		return lps;
124 	}
125 
126 	public void draw(Graphics gg) {
127 		Graphics2D g = (Graphics2D) gg;
128 		// Draw the disk in front panel
129 		Ellipse2D.Double disk = new Ellipse2D.Double(L.ScProd(e1) - pointsize
130 				/ 2, L.ScProd(e2) - pointsize / 2, pointsize, pointsize);
131 		g.setColor(color);
132 		g.fill(disk);
133 		// and drawing an outer black ring around the disk
134 		g.setColor(Color.black);
135 		g.draw(disk);
136 	}
137 
138 	public void erase(Graphics gg) {
139 		Graphics2D g = (Graphics2D) gg;
140 		// Erase the disk in front panel
141 		Ellipse2D.Double disk = new Ellipse2D.Double(L.ScProd(e1) - pointsize
142 				/ 2, L.ScProd(e2) - pointsize / 2, pointsize, pointsize);
143 		g.setColor(g.getBackground());
144 		g.fill(disk);
145 		// and erase the outer black ring around the disk
146 		g.draw(disk);
147 	}
148 
149 	public void eraseZ(Graphics gg) {
150 		Graphics2D g = (Graphics2D) gg;
151 		// Erase the disk in front panel
152 		Ellipse2D.Double disk = new Ellipse2D.Double(L.ScProd(e3) - pointsize
153 				/ 2, L.ScProd(e2) - pointsize / 2, pointsize, pointsize);
154 		g.setColor(g.getBackground());
155 		g.fill(disk);
156 		// and erase outer black ring around the disk
157 		g.draw(disk);
158 	}
159 
160 	public void drawZ(Graphics gg) {
161 		Graphics2D g = (Graphics2D) gg;
162 		// Draw the disk in front panel
163 		Ellipse2D.Double disk = new Ellipse2D.Double(L.ScProd(e3) - pointsize
164 				/ 2, L.ScProd(e2) - pointsize / 2, pointsize, pointsize);
165 		g.setColor(rightcolor);
166 		g.fill(disk);
167 		// and drawing an outer black ring around the disk
168 		g.setColor(Color.black);
169 		g.draw(disk);
170 	}
171 
172 	double ppdistance(PointC pc2) {
173 		return Math.sqrt(-2.0 * L.ScProd(pc2.getMultiVector()));
174 	}
175 
176 	public boolean isXYpoint(double x, double y) {
177 		boolean checkpoint = false;
178 		double ddxy2 = (L.ScProd(e1) - x) * (L.ScProd(e1) - x)
179 				+ (L.ScProd(e2) - y) * (L.ScProd(e2) - y);
180 		if (ddxy2 <= pointsize / 2 * pointsize / 2)
181 			checkpoint = true;
182 		return checkpoint;
183 	}
184 
185 	public boolean isYZpoint(double y, double z) {
186 		boolean checkpoint = false;
187 		double ddyz2 = (L.ScProd(e2) - y) * (L.ScProd(e2) - y)
188 				+ (L.ScProd(e3) - z) * (L.ScProd(e3) - z);
189 		if (ddyz2 <= pointsize / 2 * pointsize / 2)
190 			checkpoint = true;
191 		return checkpoint;
192 	}
193 
194 }