summaryrefslogtreecommitdiff
path: root/tags/host/0.8.1/src/org/reprap/geometry/polygons/TestMain.java
blob: ff1788ed6ce6d06f9c8f0161e2ea87f60da431ea (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

package org.reprap.geometry.polygons;

/**
 * Testing class
 */
public class TestMain
{
	public static void rrpTest()
	{
		Rr2Point p = new Rr2Point(0.1, 0.15);
		Rr2Point q = new Rr2Point(0.2, 0.85);
		Rr2Point r = new Rr2Point(1, 0.89);
		
		Rr2Point s = new Rr2Point(0.95, 0.03);
		Rr2Point pp = new Rr2Point(0.35, 0.62);
		Rr2Point qq = new Rr2Point(0.55, 0.65);
		Rr2Point rr = new Rr2Point(0.45, 0.5);
		Rr2Point ss = new Rr2Point(0.4, 0.3);    
		
		RrPolygon a = new RrPolygon();
		a.add(p, 1);
		a.add(q, 1);
		a.add(r, 1);
		a.add(s, 1);
		
		RrPolygonList c = new RrPolygonList();
		c.add(a);
		
		a = new RrPolygon();
		a.add(rr, 2);
		a.add(qq, 2);
		a.add(pp, 2);
		a.add(ss, 2);
		c.add(a);
		
		//RrPolygonList d = c.offset(0.03);
		
		//RrPolygon  e = c.hatch(x, 0.03, 3, 4);
		//d = d.offset(0.003);
		//e = e.join_up(d);
		//c.add(d); 
		//c.add(e);
		
		new RrGraphics(c, false);
	}
	
	public static RrCSGPolygon hex()
	{
		double hexSize = 10;
		double hexX = 35, hexY = 15;
		
		RrCSG r = RrCSG.universe();
		Rr2Point pold = new Rr2Point(hexX + hexSize/2, hexY);
		Rr2Point p;
		double theta = 0; 
		for(int i = 0; i < 6; i++)
		{
			theta += Math.PI * 60. / 180.0;
			p = new Rr2Point(hexX + Math.cos(theta)*hexSize/2, hexY + Math.sin(theta)*hexSize/2);
			r = RrCSG.intersection(r, new RrCSG(new RrHalfPlane(p, pold)));
			pold = p;
		}
		
		return new RrCSGPolygon(r, new RrBox(new Rr2Point(hexX - hexSize, hexY - hexSize), 
				new Rr2Point(hexX + hexSize, hexY + hexSize)));
	}
	
	public static RrCSGPolygon testPol()
	{
		Rr2Point p = new Rr2Point(0.1, 0.15);
		Rr2Point q = new Rr2Point(0.2, 0.85);
		Rr2Point r = new Rr2Point(0.97, 0.89);
		Rr2Point s = new Rr2Point(0.95, 0.03);
		
		Rr2Point pp = new Rr2Point(0.3, 0.62);
		//Rr2Point qq = new Rr2Point(0.55, 0.95);
		Rr2Point qq = new Rr2Point(0.35, 0.95);
		Rr2Point rr = new Rr2Point(0.35, 0.2);    
		
		RrHalfPlane ph = new RrHalfPlane(p, q);
		RrHalfPlane qh = new RrHalfPlane(q, r);
		RrHalfPlane rh = new RrHalfPlane(r, s);
		RrHalfPlane sh = new RrHalfPlane(s, p);
		
		RrHalfPlane pph = new RrHalfPlane(pp, qq);
		RrHalfPlane qqh = new RrHalfPlane(qq, rr);
		RrHalfPlane rrh = new RrHalfPlane(rr, pp);
		
		RrCSG pc = new RrCSG(ph);
		RrCSG qc = new RrCSG(qh);
		RrCSG rc = new RrCSG(rh);
		RrCSG sc = new RrCSG(sh);
		
		pc = RrCSG.intersection(pc, qc);
		rc = RrCSG.intersection(sc, rc);		
		pc = RrCSG.intersection(pc, rc);
		
		//RrCSG ppc = new RrCSG(pph);
		RrCSG qqc = new RrCSG(qqh);
		RrCSG rrc = new RrCSG(rrh);
		
		// ppc = RrCSG.intersection(ppc, qqc);
		RrCSG ppc = RrCSG.intersection(qqc, rrc);
		ppc = RrCSG.difference(pc, ppc);
		
		pc = ppc.offset(-0.08);
		ppc = RrCSG.difference(ppc, pc);
		
		return new RrCSGPolygon(ppc, new 
				RrBox(new Rr2Point(-0.032,-0.0176), new Rr2Point(1.317,1.12)));
	}
	
	public static void rrCSGTest()
	{
		RrCSGPolygon cp = testPol();
		//RrCSGPolygon cp = hex();
		cp.divide(1.0e-6, 1.03);
		
		//RrPolygonList pl = cp.megList(2, 3);
		//RrGraphics g = new RrGraphics(pl, false);
		//System.out.println(cp.toString());
		RrGraphics g1 = new RrGraphics(cp.box().scale(1.1), false);
		//RrHalfPlane hatch = new RrHalfPlane(new Rr2Point(1, -1), new Rr2Point(-1, 1));
		//RrHalfPlane hatch = new RrHalfPlane(new Rr2Point(1, 1), new Rr2Point(-1, -1));
		//RrPolygonList h = cp.hatch(hatch, 0.05, 3, 0);
		//System.out.println(h.toString());
		//g1.addPol(h);
		g1.addCSG(cp);
		
//		RrLine hatch = new RrLine(new Rr2Point(-1, -1), new Rr2Point(1, 1));
//		RrPolygon  h = cp.hatch_join(x, 0.005, 1, 3);
//		RrPolygonList hp;
//		hp = cp.megList(1, 0);
//		hp.add(h);
//		g.addPol(hp);  
	}
	
	public static void rrCHTest()
	{
		RrCSGPolygon cp = testPol();
		
		cp.divide(1.0e-6, 1);
		//RrGraphics g = new RrGraphics(cp, true);
		RrPolygonList hp = cp.megList(4, 3);
		System.out.println("polygons: " + hp.size());
//		RrPolygonList hpl0 = new RrPolygonList();
//		hpl0.add(hp.polygon(0));
//		hpl0.add(hp.polygon(1));
//		hpl0.add(hp.polygon(2));
//		hpl0.add(hp.polygon(3));
//		RrCSGPolygon restored = hp.toCSG();
//		restored.divide(1.0e-6, 1);
//		System.out.println(restored.toString());
		RrGraphics g = new RrGraphics(new 
				RrBox(new Rr2Point(0,0), new Rr2Point(1,1)), false);
		g.addPol(hp);
		//g.addCSG(cp);
		//g.addCSG(restored);
		
//		List chl = hp.convexHull();
//		RrPolygonList ch = new RrPolygonList();		
//		ch.add(hp.toRrPolygonHull(chl, 1));
//		g.addPol(ch);  
	}
	
	public static void main(String args[])
	{
		rrCSGTest();
		//rrCHTest();
		//rrpTest();
	}
}