Revision 85 trunk/libraries/libCq CMS for java.old/src/org/cresques/px/dxf/DxfCalArcs.java

View differences:

DxfCalArcs.java
25 25
 */
26 26
public class DxfCalArcs {
27 27

  
28
	final boolean debug = false;
28
	final boolean debug = true;
29 29
	
30 30
	final double toRad = Math.PI/(double)180.0;
31 31
	 
......
47 47
	//public DxfCalArcs(Coordinate p1, Coordinate p2, double bulge) {
48 48
	public DxfCalArcs(Point2D p1, Point2D p2, double bulge) {
49 49
		coord1 = p1;
50
		System.out.println("AAAAAAA: coord1 = " + coord1);
50 51
		coord2 = p2;
52
		System.out.println("AAAAAAA: coord2 = " + coord2);
53
		this.bulge = bulge;
54
		System.out.println("AAAAAAA: bulge = " + bulge);
51 55
		//z = p1.z;
52
		calculate(bulge);
56
		//calculate(bulge);
57
		calculate();
53 58
	}
54 59

  
55 60
	/**
......
57 62
	 * @param bulge pandeo
58 63
	 * @return El arco (this)
59 64
	 */
60
	DxfCalArcs calculate(double bulge) {
65
	//DxfCalArcs calculate(double bulge) {
66
	DxfCalArcs calculate() {
61 67
		
62
		this.bulge = bulge;
63
		
64
		 //Coordinate coordAux = new Coordinate();
65
		 Point2D coordAux = new Point2D.Double();
66
		 double d,aci,alfa,beta,landa,dd,aci2;
67

  
68
		//center = new Coordinate();
68
		Point2D coordAux = new Point2D.Double();
69 69
		center = new Point2D.Double();
70
		double d,aci,alfa,beta,landa,dd,aci2;
70 71
		d=aci=alfa=beta=landa=dd=aci2=0;
71

  
72
		
72 73
		//d = Math.sqrt((coord2.getX()-coord1.getX())*(coord2.getX()-coord1.getX()) + (coord2.getY()-coord1.getY())*(coord2.getY()-coord1.getY()) + (coord2.z-coord1.z)*(coord2.z-coord1.z));
73 74
		d = Math.sqrt((coord2.getX()-coord1.getX())*(coord2.getX()-coord1.getX()) + (coord2.getY()-coord1.getY())*(coord2.getY()-coord1.getY()));
74
		aci = Math.atan((coord2.getX()-coord1.getX())/(coord2.getY()-coord1.getY()));
75
		System.out.println("AAAAAA: d = " + d);
75 76
		
76
		if (coord2.getY() > coord1.getY())
77
			aci += Math.PI;
78

  
79 77
		coordAux.setLocation((coord1.getX()+coord2.getX())/2.0, (coord1.getY()+coord2.getY())/2.0);
80 78
		//coordAux.z = (coord1.z+coord2.z)/2.0;
79
		System.out.println("AAAAAA: coordAux = " + coordAux);			
81 80
		
82 81
		if (bulge > 0.0) {
82
			aci = Math.atan((coord2.getX()-coord1.getX())/(coord2.getY()-coord1.getY()));
83
			System.out.println("AAAAAA: aci = " + aci);						
84
			if (coord2.getY() > coord1.getY()) {
85
				aci += Math.PI;
86
				System.out.println("AAAAAA: aci = " + aci);
87
			}
88
			
83 89
			beta = Math.atan(bulge);
84 90
			alfa = beta*4.0;
85 91
			landa = alfa/2.0;
86 92
			dd = (d/2.0)/(Math.tan(landa));
87

  
88
			aci2 = aci;
93
			System.out.println("AAAAAA: dd = " + dd);
89 94
			
90
			center.setLocation(coordAux.getX() + dd*Math.sin(aci2+(Math.PI/2.0)), coordAux.getY() + dd*Math.cos(aci2+(Math.PI/2.0)));
95
			//aci2 = aci;
96
			//System.out.println("OOOOOO: aci2 = " + aci2);
97
			
98
			center.setLocation(coordAux.getX() + dd*Math.sin(aci+(Math.PI/2.0)), coordAux.getY() + dd*Math.cos(aci+(Math.PI/2.0)));
91 99
			//center.z = coordAux.z;		
92 100

  
93
			if (debug) System.out.println("CENTRO = " + center);
101
			if (debug) System.out.println("AAAAAA: center = " + center);
94 102
			
95 103
			// Calculo del Radio	
96 104
			radio = (d/2.0)/(Math.sin(landa));
......
98 106
			calculateEA(alfa);
99 107
		}
100 108
		if (bulge < 0.0) {
101
			// Aqui hay que tocar para que en vez del bulge negativo, saque el
102
			// positivo pero en el sentido de las agujas del reloj.
103
			beta = Math.atan((bulge) * (-1));
109
			bulge = bulge * (-1);
110
			System.out.println("OOOOOOo: bulge = " + bulge);
111
			aci = Math.atan((coord1.getX()-coord2.getX())/(coord1.getY()-coord2.getY()));
112
			System.out.println("OOOOOO: aci = " + aci);			
113
			if (coord2.getY() > coord1.getY()) {
114
				aci += Math.PI;
115
				System.out.println("OOOOOO: aci = " + aci);
116
			}
117
			
118
			beta = Math.atan(bulge);
104 119
			alfa = beta*4.0;
105 120
			landa = alfa/2.0;
121
			// Cuidado con dd. Cambia de un modo mu raro.
106 122
			dd = (d/2.0)/(Math.tan(landa));
107

  
108
			aci2 = aci;
123
			System.out.println("OOOOOO: dd = " + dd);			
109 124
			
110
			center.setLocation(coordAux.getX() + dd*Math.sin(aci2-(Math.PI/2.0)), coordAux.getY() + dd*Math.cos(aci2-(Math.PI/2.0)));
111
			//center.z = coordAux.z;		
112

  
113
			if (debug) System.out.println("CENTRO = " + center);
125
			//aci2 = aci;
126
			//System.out.println("OOOOOO: aci2 = " + aci2);
114 127
			
128
			// El centro lo calcula donde le da la gana.
129
			center.setLocation(coordAux.getX() + dd*Math.sin(aci+(Math.PI/2.0)), coordAux.getY() + dd*Math.cos(aci+(Math.PI/2.0)));
130
			
131
			if (debug) System.out.println("OOOOOO: center = " + center);
132
			
115 133
			// Calculo del Radio	
116 134
			radio = (d/2.0)/(Math.sin(landa));
117 135
			
118
			calculateEAInverse(alfa);
136
			//calculateEAInverse(alfa);
137
			calculateEA(alfa);
119 138
		}
120 139
		return this;		
121 140
	}
......
233 252
			}
234 253
			//angulo = acaba;
235 254
			
236
			if (bulge > 0.0) {
255
			/*if (bulge > 0.0) {
237 256
				addNode(arc, acaba, z, "POS acaba ");				
238 257
			}
239 258
			if (bulge < 0.0){
240 259
				addNode(arc, empieza, z, "POS acaba ");
241
			}
242
			//addNode(arc, acaba, z, "POS acaba ");
260
			}*/
261
			addNode(arc, acaba, z, "POS acaba ");
243 262
			
244 263
			//Coordinate aux = new Coordinate();
245 264
			Point2D aux = new Point2D.Double();
......
249 268
			double aux1 = Math.abs(aux.getX()-coord2.getX());
250 269
			double aux2 = Math.abs(aux.getY()-coord2.getY());
251 270
			if (aux1<=0.000005 && aux2<=0.000005) {
252
				//arc.remove(arc.size()-1);
253 271
				arc.remove(arc.size()-1);
272
				arc.remove(arc.size()-1);
254 273
				//arc.add(coord2);
255 274
				arc.add(coord2);
256 275
			}				
......
266 285
				addNode(arc, angulo, z, "NEG ");
267 286
			}
268 287
			
269
			if (bulge > 0.0) {
288
			/*if (bulge > 0.0) {
270 289
				angulo = acaba;
271 290
				addNode(arc, angulo, z, "NEG ");
272 291
			}
273 292
			if (bulge < 0.0) {
274 293
				angulo = empieza;
275 294
				addNode(arc, angulo, z, "NEG ");
276
			}
295
			}*/
277 296
			//angulo = acaba;
278
			//addNode(arc, angulo, z, "NEG ");
297
			addNode(arc, angulo, z, "NEG ");
279 298
			
280 299
			//Coordinate aux = new Coordinate();
281 300
			Point2D aux = new Point2D.Double();
......
284 303
			double aux1 = Math.abs(aux.getX()-coord2.getX());
285 304
			double aux2 = Math.abs(aux.getY()-coord2.getY());
286 305
			if (aux1<=0.000005 && aux2<=0.000005) {
287
				//arc.remove(arc.size()-1);
288 306
				arc.remove(arc.size()-1);
289
				//arc.remove(arc.size()-1);
290 307
				arc.remove(arc.size()-1);
291
				//arc.add(coord2);
292 308
				arc.add(coord2);
293 309
			}
294 310
		}
......
340 356
		
341 357
		double yy;
342 358
		double xx;
359
		
343 360
		yy = center.getY() + radio * Math.sin(angulo*toRad);
344 361
		xx = center.getX() + radio * Math.cos(angulo*toRad);		
345 362
		//System.out.println("xx = " + xx + ", yy = " + yy + ", arc = " + arc);

Also available in: Unified diff