Revision 39013
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/CorruptedDwgEntityException.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 01-feb-2007 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id$ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.1.2.2 2007-03-21 19:49:16 azabala |
|
49 |
* implementation of dwg 12, 13, 14. |
|
50 |
* |
|
51 |
* Revision 1.1 2007/02/01 20:00:27 azabala |
|
52 |
* *** empty log message *** |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
package org.gvsig.dwg.lib; |
|
57 |
|
|
58 |
public class CorruptedDwgEntityException extends Exception { |
|
59 |
|
|
60 |
public CorruptedDwgEntityException(String string) { |
|
61 |
super(string); |
|
62 |
} |
|
63 |
|
|
64 |
} |
|
65 |
|
|
0 | 66 |
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/IDwgVertex.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 04-mar-2007 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id$ |
|
47 |
* $Log$ |
|
48 |
* Revision 1.2.2.1 2007-03-21 19:49:16 azabala |
|
49 |
* implementation of dwg 12, 13, 14. |
|
50 |
* |
|
51 |
* Revision 1.2 2007/03/20 19:55:27 azabala |
|
52 |
* source code cleaning |
|
53 |
* |
|
54 |
* Revision 1.1 2007/03/06 19:39:38 azabala |
|
55 |
* Changes to adapt dwg 12 to general architecture |
|
56 |
* |
|
57 |
* |
|
58 |
*/ |
|
59 |
package org.gvsig.dwg.lib; |
|
60 |
|
|
61 |
/** |
|
62 |
* Base interface for all DWG vertices. |
|
63 |
* |
|
64 |
* @author azabala |
|
65 |
* |
|
66 |
* */ |
|
67 |
public interface IDwgVertex { |
|
68 |
public double[] getPoint(); |
|
69 |
public void setPoint(double[] point); |
|
70 |
} |
|
71 |
|
|
0 | 72 |
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/DwgHeader.java | ||
---|---|---|
1 |
/* jdwglib. Java Library for reading Dwg files. |
|
2 |
* |
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com). |
|
4 |
* Port from the Pythoncad Dwg library by Art Haas. |
|
5 |
* |
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Jose Morell (jose.morell@gmail.com) |
|
25 |
* |
|
26 |
* or |
|
27 |
* |
|
28 |
* IVER TI S.A. |
|
29 |
* C/Salamanca, 50 |
|
30 |
* 46005 Valencia |
|
31 |
* Spain |
|
32 |
* +34 963163400 |
|
33 |
* dac@iver.es |
|
34 |
*/ |
|
35 |
package org.gvsig.dwg.lib; |
|
36 |
|
|
37 |
/** |
|
38 |
* The DwgHeader class implements the Header of a DWG file |
|
39 |
* |
|
40 |
* @author jmorell |
|
41 |
*/ |
|
42 |
public class DwgHeader { |
|
43 |
} |
|
0 | 44 |
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/util/Matrix4D.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.dwg.lib.util; |
|
3 |
|
|
4 |
|
|
5 |
/** |
|
6 |
* 4x4dim double matrix used for perspective transformations. |
|
7 |
* The class is now declared final to allow a more aggresive optimization. |
|
8 |
* |
|
9 |
*/ |
|
10 |
public final class Matrix4D { |
|
11 |
static private final double DEG2RAD = Math.PI/180.0; // conversion from degree to radians |
|
12 |
|
|
13 |
public double xx, xy, xz, xw, // 1st row |
|
14 |
yx, yy, yz, yw, // 2nd row |
|
15 |
zx, zy, zz, zw, // 3rd row |
|
16 |
wx, wy, wz, ww; // 4th row |
|
17 |
|
|
18 |
/** |
|
19 |
* Create identity matrix. |
|
20 |
*/ |
|
21 |
public Matrix4D() { |
|
22 |
// set to identity mat |
|
23 |
xx = yy = zz = ww = 1f; |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* Copy constructor. |
|
28 |
* @param m matrix to copy |
|
29 |
*/ |
|
30 |
public Matrix4D(Matrix4D m) { |
|
31 |
xx = m.xx; |
|
32 |
xy = m.xy; |
|
33 |
xz = m.xz; |
|
34 |
xw = m.xw; |
|
35 |
yx = m.yx; |
|
36 |
yy = m.yy; |
|
37 |
yz = m.yz; |
|
38 |
yw = m.yw; |
|
39 |
zx = m.zx; |
|
40 |
zy = m.zy; |
|
41 |
zz = m.zz; |
|
42 |
zw = m.zw; |
|
43 |
wx = m.wx; |
|
44 |
wy = m.wy; |
|
45 |
wz = m.wz; |
|
46 |
ww = m.ww; |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* @param mxx 1st elem in 1st row |
|
51 |
* @param mxy 2nd elem in 1st row |
|
52 |
* @param mxz 3rd elem in 1st row |
|
53 |
* @param mxw 4th elem in 1st row |
|
54 |
* @param myx 1st elem in 2nd row |
|
55 |
* @param myy 2nd elem in 2nd row |
|
56 |
* @param myz 3rd elem in 2nd row |
|
57 |
* @param myw 4th elem in 2nd row |
|
58 |
* @param mzx 1st elem in 3rd row |
|
59 |
* @param mzy 2nd elem in 3rd row |
|
60 |
* @param mzz 3rd elem in 3rd row |
|
61 |
* @param mzw 4th elem in 3rd row |
|
62 |
* @param mwx 1st elem in 4th row |
|
63 |
* @param mwy 2nd elem in 4th row |
|
64 |
* @param mwz 3rd elem in 4th row |
|
65 |
* @param mww 4th elem in 4th row |
|
66 |
*/ |
|
67 |
public Matrix4D(double mxx, double mxy, double mxz, double mxw, |
|
68 |
double myx, double myy, double myz, double myw, |
|
69 |
double mzx, double mzy, double mzz, double mzw, |
|
70 |
double mwx, double mwy, double mwz, double mww) { |
|
71 |
xx = mxx; |
|
72 |
xy = mxy; |
|
73 |
xz = mxz; |
|
74 |
xw = mxw; |
|
75 |
yx = myx; |
|
76 |
yy = myy; |
|
77 |
yz = myz; |
|
78 |
yw = myw; |
|
79 |
zx = mzx; |
|
80 |
zy = mzy; |
|
81 |
zz = mzz; |
|
82 |
zw = mzw; |
|
83 |
wx = mwx; |
|
84 |
wy = mwy; |
|
85 |
wz = mwz; |
|
86 |
ww = mww; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Reset to identity |
|
91 |
*/ |
|
92 |
public void identity() { |
|
93 |
xx = yy = zz = ww = 1f; |
|
94 |
xy = xz = xw = |
|
95 |
yx = yz = yw = |
|
96 |
zx = zy = zw = |
|
97 |
wx = wy = wz = 0f; |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Transponize. |
|
102 |
*/ |
|
103 |
public void transponize() { |
|
104 |
// switch rows and columns |
|
105 |
double t; |
|
106 |
t = xy; xy = yx; yx = t; |
|
107 |
t = xz; xz = zx; zx = t; |
|
108 |
t = xw; xw = wx; wx = t; |
|
109 |
t = yz; yz = zy; zy = t; |
|
110 |
t = yw; yw = wy; wy = t; |
|
111 |
t = zw; zw = wz; wz = t; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Matrix multiplication of vector. |
|
116 |
* @param v vector to transform |
|
117 |
* @return transformed vector |
|
118 |
*/ |
|
119 |
public Vector3D mult(Vector3D v) { |
|
120 |
return new Vector3D(xx*v.x + xy*v.y + xz*v.z, |
|
121 |
yx*v.x + yy*v.y + yz*v.z, |
|
122 |
zx*v.x + zy*v.y + zz*v.z); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Transformation of 1 vector. |
|
127 |
* @param v vector to transform |
|
128 |
*/ |
|
129 |
public void transform(Vector3D v) { |
|
130 |
double x = xx*v.x + xy*v.y + xz*v.z, |
|
131 |
y = yx*v.x + yy*v.y + yz*v.z, |
|
132 |
z = zx*v.x + zy*v.y + zz*v.z; |
|
133 |
|
|
134 |
v.x = x; |
|
135 |
v.y = y; |
|
136 |
v.z = z; |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Matrix multiplication of point. |
|
141 |
* @param p point to transform |
|
142 |
* @return transformed point |
|
143 |
*/ |
|
144 |
public Point3D mult(Point3D p) { |
|
145 |
Point3D ret = new Point3D(xx*p.x + xy*p.y + xz*p.z + xw, |
|
146 |
yx*p.x + yy*p.y + yz*p.z + yw, |
|
147 |
zx*p.x + zy*p.y + zz*p.z + zw); |
|
148 |
ret.scale(1f/(wx*p.x + wy*p.y + wz*p.z + ww)); |
|
149 |
return ret; |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Transformation of 1 point. |
|
154 |
* @param p point to transform |
|
155 |
*/ |
|
156 |
public void transform(Point3D p) { |
|
157 |
double x = xx*p.x + xy*p.y + xz*p.z + xw, |
|
158 |
y = yx*p.x + yy*p.y + yz*p.z + yw, |
|
159 |
z = zx*p.x + zy*p.y + zz*p.z + zw, |
|
160 |
w = wx*p.x + wy*p.y + wz*p.z + ww; |
|
161 |
|
|
162 |
p.x = x/w; |
|
163 |
p.y = y/w; |
|
164 |
p.z = z/w; |
|
165 |
} |
|
166 |
|
|
167 |
/**Transformacion de un punto considerando solo el plano horizontal |
|
168 |
*/ |
|
169 |
public void transformXY(Point3D p){ |
|
170 |
double x = xx*p.x + xy*p.y+ xw, |
|
171 |
y = yx*p.x + yy*p.y + yw, |
|
172 |
w = wx*p.x + wy*p.y + ww; |
|
173 |
p.x = x/w; |
|
174 |
p.y = y/w; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* Matrix multiplication. |
|
179 |
* @param m matrix to multiply with |
|
180 |
* @return this * m |
|
181 |
*/ |
|
182 |
public Matrix4D mult(Matrix4D m) { |
|
183 |
if (m != null) { |
|
184 |
return new Matrix4D(xx*m.xx + xy*m.yx + xz*m.zx + xw*m.wx, |
|
185 |
xx*m.xy + xy*m.yy + xz*m.zy + xw*m.wy, |
|
186 |
xx*m.xz + xy*m.yz + xz*m.zz + xw*m.wz, |
|
187 |
xx*m.xw + xy*m.yw + xz*m.zw + xw*m.ww, |
|
188 |
yx*m.xx + yy*m.yx + yz*m.zx + yw*m.wx, |
|
189 |
yx*m.xy + yy*m.yy + yz*m.zy + yw*m.wy, |
|
190 |
yx*m.xz + yy*m.yz + yz*m.zz + yw*m.wz, |
|
191 |
yx*m.xw + yy*m.yw + yz*m.zw + yw*m.ww, |
|
192 |
zx*m.xx + zy*m.yx + zz*m.zx + zw*m.wx, |
|
193 |
zx*m.xy + zy*m.yy + zz*m.zy + zw*m.wy, |
|
194 |
zx*m.xz + zy*m.yz + zz*m.zz + zw*m.wz, |
|
195 |
zx*m.xw + zy*m.yw + zz*m.zw + zw*m.ww, |
|
196 |
wx*m.xx + wy*m.yx + wz*m.zx + ww*m.wx, |
|
197 |
wx*m.xy + wy*m.yy + wz*m.zy + ww*m.wy, |
|
198 |
wx*m.xz + wy*m.yz + wz*m.zz + ww*m.wz, |
|
199 |
wx*m.xw + wy*m.yw + wz*m.zw + ww*m.ww); |
|
200 |
} |
|
201 |
else { |
|
202 |
return new Matrix4D(this); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Matrix multiplication. |
|
208 |
* @param m matrix to multply with |
|
209 |
*/ |
|
210 |
public void multBy(Matrix4D m) { |
|
211 |
double x = xx*m.xx + xy*m.yx + xz*m.zx + xw*m.wx, |
|
212 |
y = xx*m.xy + xy*m.yy + xz*m.zy + xw*m.wy, |
|
213 |
z = xx*m.xz + xy*m.yz + xz*m.zz + xw*m.wz, |
|
214 |
w = xx*m.xw + xy*m.yw + xz*m.zw + xw*m.ww; |
|
215 |
xx = x; |
|
216 |
xy = y; |
|
217 |
xz = z; |
|
218 |
xw = w; |
|
219 |
|
|
220 |
x = yx*m.xx + yy*m.yx + yz*m.zx + yw*m.wx; |
|
221 |
y = yx*m.xy + yy*m.yy + yz*m.zy + yw*m.wy; |
|
222 |
z = yx*m.xz + yy*m.yz + yz*m.zz + yw*m.wz; |
|
223 |
w = yx*m.xw + yy*m.yw + yz*m.zw + yw*m.ww; |
|
224 |
yx = x; |
|
225 |
yy = y; |
|
226 |
yz = z; |
|
227 |
yw = w; |
|
228 |
|
|
229 |
x = zx*m.xx + zy*m.yx + zz*m.zx + zw*m.wx; |
|
230 |
y = zx*m.xy + zy*m.yy + zz*m.zy + zw*m.wy; |
|
231 |
z = zx*m.xz + zy*m.yz + zz*m.zz + zw*m.wz; |
|
232 |
w = zx*m.xw + zy*m.yw + zz*m.zw + zw*m.ww; |
|
233 |
zx = x; |
|
234 |
zy = y; |
|
235 |
zz = z; |
|
236 |
zw = w; |
|
237 |
|
|
238 |
x = wx*m.xx + wy*m.yx + wz*m.zx + ww*m.wx; |
|
239 |
y = wx*m.xy + wy*m.yy + wz*m.zy + ww*m.wy; |
|
240 |
z = wx*m.xz + wy*m.yz + wz*m.zz + ww*m.wz; |
|
241 |
w = wx*m.xw + wy*m.yw + wz*m.zw + ww*m.ww; |
|
242 |
wx = x; |
|
243 |
wy = y; |
|
244 |
wz = z; |
|
245 |
ww = w; |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* Matrix multiplication from left. |
|
250 |
* @param m matrix to multiply with. |
|
251 |
*/ |
|
252 |
public void multLeftBy(Matrix4D m) { |
|
253 |
double x = m.xx*xx + m.xy*yx + m.xz*zx + m.xw*wx, |
|
254 |
y = m.yx*xx + m.yy*yx + m.yz*zx + m.yw*wx, |
|
255 |
z = m.zx*xx + m.zy*yx + m.zz*zx + m.zw*wx, |
|
256 |
w = m.wx*xx + m.wy*yx + m.wz*zx + m.ww*wx; |
|
257 |
xx = x; |
|
258 |
yx = y; |
|
259 |
zx = z; |
|
260 |
wx = w; |
|
261 |
|
|
262 |
x = m.xx*xy + m.xy*yy + m.xz*zy + m.xw*wy; |
|
263 |
y = m.yx*xy + m.yy*yy + m.yz*zy + m.yw*wy; |
|
264 |
z = m.zx*xy + m.zy*yy + m.zz*zy + m.zw*wy; |
|
265 |
w = m.wx*xy + m.wy*yy + m.wz*zy + m.ww*wy; |
|
266 |
xy = x; |
|
267 |
yy = y; |
|
268 |
zy = z; |
|
269 |
wy = w; |
|
270 |
|
|
271 |
x = m.xx*xz + m.xy*yz + m.xz*zz + m.xw*wz; |
|
272 |
y = m.yx*xz + m.yy*yz + m.yz*zz + m.yw*wz; |
|
273 |
z = m.zx*xz + m.zy*yz + m.zz*zz + m.zw*wz; |
|
274 |
w = m.wx*xz + m.wy*yz + m.wz*zz + m.ww*wz; |
|
275 |
xz = x; |
|
276 |
yz = y; |
|
277 |
zz = z; |
|
278 |
wz = w; |
|
279 |
|
|
280 |
x = m.xx*xw + m.xy*yw + m.xz*zw + m.xw*ww; |
|
281 |
y = m.yx*xw + m.yy*yw + m.yz*zw + m.yw*ww; |
|
282 |
z = m.zx*xw + m.zy*yw + m.zz*zw + m.zw*ww; |
|
283 |
w = m.wx*xw + m.wy*yw + m.wz*zw + m.ww*ww; |
|
284 |
xw = x; |
|
285 |
yw = y; |
|
286 |
zw = z; |
|
287 |
ww = w; |
|
288 |
} |
|
289 |
|
|
290 |
/** |
|
291 |
* Translate the origin. |
|
292 |
* @param x translation in x |
|
293 |
* @param y translation in y |
|
294 |
* @param z translation in z |
|
295 |
*/ |
|
296 |
public void translate(double x, double y, double z) { |
|
297 |
xw += x*xx+y*xy+z*xz; |
|
298 |
yw += x*yx+y*yy+z*yz; |
|
299 |
zw += x*zx+y*zy+z*zz; |
|
300 |
ww += x*wx+y*wy+z*wz; |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Translate the origin |
|
305 |
* @param v translation vector |
|
306 |
*/ |
|
307 |
public void translate(Vector3D v) { |
|
308 |
translate(v.x, v.y, v.z); |
|
309 |
} |
|
310 |
|
|
311 |
/** |
|
312 |
* Translate. |
|
313 |
* @param x translation in x |
|
314 |
* @param y translation in y |
|
315 |
* @param z translation in z |
|
316 |
*/ |
|
317 |
public void translateLeft(double x, double y, double z) { |
|
318 |
if (x != 0f) { |
|
319 |
xx += x*wx; xy += x*wy; xz += x*wz; xw += x*ww; |
|
320 |
} |
|
321 |
if (y != 0f) { |
|
322 |
yx += y*wx; yy += y*wy; yz += y*wz; yw += y*ww; |
|
323 |
} |
|
324 |
if (z != 0f) { |
|
325 |
zx += z*wx; zy += z*wy; zz += z*wz; zw += z*ww; |
|
326 |
} |
|
327 |
} |
|
328 |
|
|
329 |
/** |
|
330 |
* Translate the origin |
|
331 |
* @param v tranbslation vector |
|
332 |
*/ |
|
333 |
public void translateLeft(Vector3D v) { |
|
334 |
translateLeft(v.x, v.y, v.z); |
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
/** |
|
339 |
* Move the stuff. |
|
340 |
* @param x translation in x |
|
341 |
* @param y translation in y |
|
342 |
* @param z translation in z |
|
343 |
*/ |
|
344 |
public void moveBy(double x, double y, double z) { |
|
345 |
if (x != 0f) { |
|
346 |
xx += x*xw; yx += x*yw; zx += x*zw; wx += x*ww; |
|
347 |
} |
|
348 |
if (y != 0f) { |
|
349 |
xy += y*xw; yy += y*yw; zy += y*zw; wy += y*ww; |
|
350 |
} |
|
351 |
if (z != 0f) { |
|
352 |
xz += z*xw; yz += z*yw; zz += z*zw; wz += z*ww; |
|
353 |
} |
|
354 |
} |
|
355 |
|
|
356 |
/** |
|
357 |
* Translate the origin |
|
358 |
* @param v translation vector |
|
359 |
*/ |
|
360 |
public void moveBy(Vector3D v) { |
|
361 |
moveBy(v.x, v.y, v.z); |
|
362 |
} |
|
363 |
|
|
364 |
|
|
365 |
/** |
|
366 |
* Rotate theta degrees about the y axis. |
|
367 |
* @param theta rotation angle in rad |
|
368 |
*/ |
|
369 |
public void yrot(double theta) { |
|
370 |
if (theta == 0.0) { |
|
371 |
return; |
|
372 |
} |
|
373 |
double ct = Math.cos(theta); |
|
374 |
double st = -Math.sin(theta); |
|
375 |
|
|
376 |
double Nx = (double) (xx * ct - zx * st); |
|
377 |
double Nz = (double) (xx * st + zx * ct); |
|
378 |
xx = Nx; |
|
379 |
zx = Nz; |
|
380 |
|
|
381 |
Nx = (double) (xy * ct - zy * st); |
|
382 |
Nz = (double) (xy * st + zy * ct); |
|
383 |
xy = Nx; |
|
384 |
zy = Nz; |
|
385 |
|
|
386 |
Nx = (double) (xz * ct - zz * st); |
|
387 |
Nz = (double) (xz * st + zz * ct); |
|
388 |
xz = Nx; |
|
389 |
zz = Nz; |
|
390 |
|
|
391 |
Nx = (double) (xw * ct - zw * st); |
|
392 |
Nz = (double) (xw * st + zw * ct); |
|
393 |
xw = Nx; |
|
394 |
zw = Nz; |
|
395 |
} |
|
396 |
|
|
397 |
/** |
|
398 |
* Rotate theta degrees about the x axis. |
|
399 |
* @param theta rotation angle in rad |
|
400 |
*/ |
|
401 |
public void xrot(double theta) { |
|
402 |
if (theta == 0.0) { |
|
403 |
return; |
|
404 |
} |
|
405 |
double ct = Math.cos(theta); |
|
406 |
double st = Math.sin(theta); |
|
407 |
|
|
408 |
double Ny = (double) (yx * ct - zx * st); |
|
409 |
double Nz = (double) (yx * st + zx * ct); |
|
410 |
yx = Ny; |
|
411 |
zx = Nz; |
|
412 |
|
|
413 |
Ny = (double) (yy * ct - zy * st); |
|
414 |
Nz = (double) (yy * st + zy * ct); |
|
415 |
yy = Ny; |
|
416 |
zy = Nz; |
|
417 |
|
|
418 |
Ny = (double) (yz * ct - zz * st); |
|
419 |
Nz = (double) (yz * st + zz * ct); |
|
420 |
yz = Ny; |
|
421 |
zz = Nz; |
|
422 |
|
|
423 |
Ny = (double) (yw * ct - zw * st); |
|
424 |
Nz = (double) (yw * st + zw * ct); |
|
425 |
yw = Ny; |
|
426 |
zw = Nz; |
|
427 |
} |
|
428 |
|
|
429 |
/** |
|
430 |
* Rotate theta degrees about the z axis. |
|
431 |
* @param theta rotation angle in rad |
|
432 |
*/ |
|
433 |
public void zrot(double theta) { |
|
434 |
if (theta == 0.0) { |
|
435 |
return; |
|
436 |
} |
|
437 |
double ct = Math.cos(theta); |
|
438 |
double st = Math.sin(theta); |
|
439 |
|
|
440 |
double Nx = (double) (xx * ct - yx * st); |
|
441 |
double Ny = (double) (xx * st + yx * ct); |
|
442 |
xx = Nx; |
|
443 |
yx = Ny; |
|
444 |
|
|
445 |
Nx = (double) (xy * ct - yy * st); |
|
446 |
Ny = (double) (xy * st + yy * ct); |
|
447 |
xy = Nx; |
|
448 |
yy = Ny; |
|
449 |
|
|
450 |
Nx = (double) (xz * ct - yz * st); |
|
451 |
Ny = (double) (xz * st + yz * ct); |
|
452 |
xz = Nx; |
|
453 |
yz = Ny; |
|
454 |
|
|
455 |
Nx = (double) (xw * ct - yw * st); |
|
456 |
Ny = (double) (xw * st + yw * ct); |
|
457 |
xw = Nx; |
|
458 |
yw = Ny; |
|
459 |
} |
|
460 |
|
|
461 |
/** |
|
462 |
* Scale. |
|
463 |
* @param f factor to scale with. |
|
464 |
*/ |
|
465 |
public void scale(double f) { |
|
466 |
xx *= f; |
|
467 |
yx *= f; |
|
468 |
zx *= f; |
|
469 |
wx *= f; |
|
470 |
xy *= f; |
|
471 |
yy *= f; |
|
472 |
zy *= f; |
|
473 |
wy *= f; |
|
474 |
xz *= f; |
|
475 |
yz *= f; |
|
476 |
zz *= f; |
|
477 |
wz *= f; |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Scale different in x,y,z. |
|
482 |
* @param fx scaling factor in x |
|
483 |
* @param fy scaling factor in y |
|
484 |
* @param fz scaling factor in z |
|
485 |
*/ |
|
486 |
public void scale(double fx, double fy, double fz) { |
|
487 |
xx *= fx; |
|
488 |
yx *= fx; |
|
489 |
zx *= fx; |
|
490 |
wx *= fx; |
|
491 |
xy *= fy; |
|
492 |
yy *= fy; |
|
493 |
zy *= fy; |
|
494 |
wy *= fy; |
|
495 |
xz *= fz; |
|
496 |
yz *= fz; |
|
497 |
zz *= fz; |
|
498 |
wz *= fz; |
|
499 |
} |
|
500 |
|
|
501 |
|
|
502 |
private static final double MIN_INT = (double)Short.MIN_VALUE; |
|
503 |
private static final double MAX_INT = (double)Short.MAX_VALUE; |
|
504 |
|
|
505 |
/** |
|
506 |
* Transform some points. |
|
507 |
* @param v points to transform |
|
508 |
* @param tx transformed points x coord |
|
509 |
* @param ty transformed points y coord |
|
510 |
* @param tz transformed points z coord |
|
511 |
* @param npoints nr of points to transform |
|
512 |
*/ |
|
513 |
public void transform(Point3D v[], int tx[], int ty[], int tz[], int npoints) { |
|
514 |
Point3D tmp; |
|
515 |
|
|
516 |
for (int i = npoints; --i >= 0;) { |
|
517 |
tmp = mult(v[i]); |
|
518 |
|
|
519 |
if (tmp.x < MIN_INT) { |
|
520 |
tmp.x = MIN_INT; |
|
521 |
} |
|
522 |
else if (tmp.x > MAX_INT) { |
|
523 |
tmp.x = MAX_INT; |
|
524 |
} |
|
525 |
if (tmp.y < MIN_INT) { |
|
526 |
tmp.y = MIN_INT; |
|
527 |
} |
|
528 |
else if (tmp.y > MAX_INT) { |
|
529 |
tmp.y = MAX_INT; |
|
530 |
} |
|
531 |
if (tmp.z < MIN_INT) { |
|
532 |
tmp.z = MIN_INT; |
|
533 |
} |
|
534 |
else if (tmp.z > MAX_INT) { |
|
535 |
tmp.z = MAX_INT; |
|
536 |
} |
|
537 |
|
|
538 |
tx[i] = (int) tmp.x; |
|
539 |
ty[i] = (int) tmp.y; |
|
540 |
tz[i] = (int) tmp.z; |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
/** |
|
545 |
* Output |
|
546 |
* @return String representing this. |
|
547 |
*/ |
|
548 |
public String toString() { |
|
549 |
return new String(new StringBuffer().append("{{"). |
|
550 |
append(xx).append(",").append(xy).append(",").append(xz).append(",").append(xw). |
|
551 |
append("},{"). |
|
552 |
append(yx).append(",").append(yy).append(",").append(yz).append(",").append(yw). |
|
553 |
append("},{"). |
|
554 |
append(zx).append(",").append(zy).append(",").append(zz).append(",").append(zw). |
|
555 |
append("},{"). |
|
556 |
append(wx).append(",").append(wy).append(",").append(wz).append(",").append(ww). |
|
557 |
append("}}")); |
|
558 |
} |
|
559 |
} |
|
560 |
|
|
561 |
|
|
0 | 562 |
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/util/Point3D.java | ||
---|---|---|
1 |
/* |
|
2 |
* |
|
3 |
* Este codigo se distribuye bajo licencia GPL |
|
4 |
* de GNU. Para obtener una c?pia integra de esta |
|
5 |
* licencia acude a www.gnu.org. |
|
6 |
* |
|
7 |
* Este software se distribuye "como es". AGIL |
|
8 |
* solo pretende desarrollar herramientas para |
|
9 |
* la promoci?n del GIS Libre. |
|
10 |
* AGIL no se responsabiliza de las perdidas econ?micas o de |
|
11 |
* informaci?n derivadas del uso de este software. |
|
12 |
*/ |
|
13 |
|
|
14 |
|
|
15 |
package org.gvsig.dwg.lib.util; |
|
16 |
|
|
17 |
/** |
|
18 |
* 3dim double point. A point is transformed different than a vector. |
|
19 |
* The class is now declared final to allow a more aggresive optimization. |
|
20 |
* |
|
21 |
* @see dxfviewer.math.Vector3D; |
|
22 |
* |
|
23 |
* @version 1.10,?01/13/99 |
|
24 |
*/ |
|
25 |
public final class Point3D { |
|
26 |
public double x, y, z; // coordinates, allowing direct access |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
public Point3D() { |
|
32 |
} |
|
33 |
|
|
34 |
/** |
|
35 |
* Copy constructor. |
|
36 |
* @param p point to copy |
|
37 |
*/ |
|
38 |
public Point3D(Point3D p) { |
|
39 |
x = p.x; |
|
40 |
y = p.y; |
|
41 |
z = p.z; |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* @param xx x coord |
|
46 |
* @param yy y coord |
|
47 |
* @param zz z coord |
|
48 |
*/ |
|
49 |
public Point3D(double xx, double yy, double zz) { |
|
50 |
x = xx; |
|
51 |
y = yy; |
|
52 |
z = zz; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Scale. |
|
57 |
* @param f scaling factor |
|
58 |
*/ |
|
59 |
public void scale(double f) { |
|
60 |
if (f != 1f) { |
|
61 |
x *= f; |
|
62 |
y *= f; |
|
63 |
z *= f; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* Add a vector. |
|
69 |
* @param v vector to add |
|
70 |
*/ |
|
71 |
public void add(Vector3D v) { |
|
72 |
x += v.x; |
|
73 |
y += v.y; |
|
74 |
z += v.z; |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Get sum with vector. |
|
79 |
* @param v vector to add |
|
80 |
* @return this+v |
|
81 |
*/ |
|
82 |
public Point3D plus(Vector3D v) { |
|
83 |
Point3D ret = new Point3D(this); |
|
84 |
ret.add(v); |
|
85 |
return ret; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Substract a vector. |
|
90 |
* @param v vector to substract |
|
91 |
*/ |
|
92 |
public void sub(Vector3D v) { |
|
93 |
x -= v.x; |
|
94 |
y -= v.y; |
|
95 |
z -= v.z; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Get difference with vector. |
|
100 |
* @param v vector to substract |
|
101 |
* @return this-v |
|
102 |
*/ |
|
103 |
public Point3D minus(Vector3D v) { |
|
104 |
Point3D ret = new Point3D(this); |
|
105 |
ret.sub(v); |
|
106 |
return ret; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Get difference with point. |
|
111 |
* @param p point to substract |
|
112 |
* @return this-p |
|
113 |
*/ |
|
114 |
public Vector3D minus(Point3D p) { |
|
115 |
Vector3D ret = new Vector3D(this); |
|
116 |
ret.sub(new Vector3D(p)); |
|
117 |
return ret; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Output. |
|
122 |
* @return output string |
|
123 |
*/ |
|
124 |
public String toString() { |
|
125 |
return new String(new StringBuffer().append("[").append(x).append(",").append(y).append(",").append(z).append("]")); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
|
|
0 | 130 |
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/util/FMapUtil.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 18-ene-2007 by azabala |
|
3 |
* |
|
4 |
*/ |
|
5 |
package org.gvsig.dwg.lib.util; |
|
6 |
|
|
7 |
import java.awt.geom.Point2D; |
|
8 |
import java.util.Iterator; |
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
import org.gvsig.dwg.lib.IDwgVertex; |
|
12 |
import org.gvsig.fmap.geom.Geometry; |
|
13 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
14 |
import org.gvsig.fmap.geom.GeometryManager; |
|
15 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
16 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
17 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
18 |
import org.gvsig.fmap.geom.primitive.Point; |
|
19 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* @author alzabord |
|
24 |
* |
|
25 |
*/ |
|
26 |
public class FMapUtil { |
|
27 |
|
|
28 |
// /** |
|
29 |
// * Method that changes a Point3D array to a FPolyline3D. Is useful to |
|
30 |
// * convert a polyline given by it points to a FPolyline3D, a polyline 3D in |
|
31 |
// * the FMap model object |
|
32 |
// * |
|
33 |
// * @param pts |
|
34 |
// * Array of Point3D that defines the polyline 3D that will be |
|
35 |
// * converted in a FPolyline3D |
|
36 |
// * @return FPolyline3D This FPolyline3D is build using the array of Point3D |
|
37 |
// * that is the argument of the method |
|
38 |
// */ |
|
39 |
// public static FPolyline3D points3DToFPolyline3D(List pts) { |
|
40 |
// GeneralPathX genPathX = getGeneralPathX(pts); |
|
41 |
// double[] elevations = new double[pts.size()]; |
|
42 |
// for (int i = 0; i < pts.size(); i++) { |
|
43 |
// elevations[i] = ((double[])pts.get(i))[2]; |
|
44 |
// } |
|
45 |
// return new FPolyline3D(genPathX, elevations); |
|
46 |
// } |
|
47 |
|
|
48 |
private static GeometryManager gManager = GeometryLocator |
|
49 |
.getGeometryManager(); |
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
// /** |
|
54 |
// * Method that changes a Point2D array to a FPolyline2D. Is useful to |
|
55 |
// * convert a polyline given by it points to a FPolyline2D, a polyline in the |
|
56 |
// * FMap model object |
|
57 |
// * |
|
58 |
// * @param pts |
|
59 |
// * Array of Point2D that defines the polyline that will be |
|
60 |
// * converted in a FPolyline2D |
|
61 |
// * @return FPolyline2D This FPolyline2D is build using the array of Point2D |
|
62 |
// * that is the argument of the method |
|
63 |
// */ |
|
64 |
// public static FPolyline2D points2DToFPolyline2D(List pts) { |
|
65 |
// GeneralPathX genPathX = getGeneralPathX(pts); |
|
66 |
// return new FPolyline2D(genPathX); |
|
67 |
// } |
|
68 |
|
|
69 |
public static MultiCurve ptsToMultiCurve(List pts, int subType) |
|
70 |
throws CreateGeometryException { |
|
71 |
|
|
72 |
if (pts.size() < 2) { |
|
73 |
throw new IllegalArgumentException(); |
|
74 |
} |
|
75 |
|
|
76 |
Point point, prevPoint; |
|
77 |
Curve curve; |
|
78 |
|
|
79 |
MultiCurve multi = (MultiCurve) gManager.create( |
|
80 |
Geometry.TYPES.MULTICURVE, |
|
81 |
subType); |
|
82 |
prevPoint = FMapUtil.createPoint(subType, pts.get(0)); |
|
83 |
for (int i = 1; i < pts.size(); i++) { |
|
84 |
point = FMapUtil.createPoint(subType, pts.get(i)); |
|
85 |
curve = (Curve) gManager.create(Geometry.TYPES.CURVE, subType); |
|
86 |
curve.setPoints(prevPoint, point); |
|
87 |
multi.addCurve(curve); |
|
88 |
prevPoint = FMapUtil.createPoint(subType, pts.get(i)); |
|
89 |
} |
|
90 |
return multi; |
|
91 |
|
|
92 |
} |
|
93 |
|
|
94 |
public static Surface ptsToPolygon(List pts, int subType) |
|
95 |
throws CreateGeometryException { |
|
96 |
|
|
97 |
|
|
98 |
if (pts.size() < 3) { |
|
99 |
throw new IllegalArgumentException(); |
|
100 |
} |
|
101 |
|
|
102 |
Point cur; |
|
103 |
Surface surface = (Surface) gManager.create(Geometry.TYPES.SURFACE, |
|
104 |
subType); |
|
105 |
|
|
106 |
Iterator iter = pts.iterator(); |
|
107 |
while (iter.hasNext()) { |
|
108 |
cur = createPoint(subType, iter.next()); |
|
109 |
surface.addVertex(cur); |
|
110 |
} |
|
111 |
return surface; |
|
112 |
} |
|
113 |
|
|
114 |
public static Point createPoint(int subType, |
|
115 |
Object point) |
|
116 |
throws CreateGeometryException { |
|
117 |
Point result = (Point) gManager.create(Geometry.TYPES.POINT, subType); |
|
118 |
if (point instanceof double[]) { |
|
119 |
result.setCoordinates((double[]) point); |
|
120 |
} else if (point instanceof Point2D) { |
|
121 |
Point2D p = (Point2D) point; |
|
122 |
result.setX(p.getX()); |
|
123 |
result.setY(p.getY()); |
|
124 |
|
|
125 |
} else if (point instanceof IDwgVertex) { |
|
126 |
result.setCoordinates(((IDwgVertex) point).getPoint()); |
|
127 |
} else { |
|
128 |
throw new IllegalArgumentException(); |
|
129 |
} |
|
130 |
return result; |
|
131 |
} |
|
132 |
|
|
133 |
} |
|
0 | 134 |
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/util/ArcFromBulgeCalculator.java | ||
---|---|---|
1 |
/* jdwglib. Java Library for reading Dwg files. |
|
2 |
* |
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com). |
|
4 |
* Port from the Pythoncad Dwg library by Art Haas. |
|
5 |
* |
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Jose Morell (jose.morell@gmail.com) |
|
25 |
* |
|
26 |
* or |
|
27 |
* |
|
28 |
* IVER TI S.A. |
|
29 |
* C/Salamanca, 50 |
|
30 |
* 46005 Valencia |
|
31 |
* Spain |
|
32 |
* +34 963163400 |
|
33 |
* dac@iver.es |
|
34 |
*/ |
|
35 |
package org.gvsig.dwg.lib.util; |
|
36 |
|
|
37 |
import java.awt.geom.Point2D; |
|
38 |
import java.util.Vector; |
|
39 |
|
|
40 |
/** |
|
41 |
* This class calculates an arc given by a start and end points and a bulge |
|
42 |
* |
|
43 |
* @author jmorell |
|
44 |
*/ |
|
45 |
public class ArcFromBulgeCalculator { |
|
46 |
private double[] coord1, coord2; |
|
47 |
private double[] center; |
|
48 |
private double radio, empieza, acaba; |
|
49 |
private double bulge; |
|
50 |
private double d, dd, aci; |
|
51 |
private double[] coordAux; |
|
52 |
|
|
53 |
/** |
|
54 |
* This method calculates an arc given by a start and end points and a bulge |
|
55 |
* |
|
56 |
* @param p1 Start point of the arc given by a Point2D |
|
57 |
* @param p2 End point of the arc given by a Point2D |
|
58 |
* @param bulge Bulge of the arc given by a double value |
|
59 |
*/ |
|
60 |
public ArcFromBulgeCalculator(double[] p1, double[] p2, double bulge) { |
|
61 |
this.bulge = bulge; |
|
62 |
if (bulge < 0.0) { |
|
63 |
coord1 = p2; |
|
64 |
coord2 = p1; |
|
65 |
} else { |
|
66 |
coord1 = p1; |
|
67 |
coord2 = p2; |
|
68 |
} |
|
69 |
calParams(); |
|
70 |
} |
|
71 |
|
|
72 |
private void calParams() { |
|
73 |
d = Math.sqrt((coord2[0]-coord1[0])*(coord2[0]-coord1[0]) + |
|
74 |
(coord2[1]-coord1[1])*(coord2[1]-coord1[1])); |
|
75 |
coordAux = new double[]{(coord1[0]+coord2[0])/2.0, (coord1[1]+coord2[1])/2.0}; |
|
76 |
double b = Math.abs(bulge); |
|
77 |
double beta = Math.atan(b); |
|
78 |
double alfa = beta*4.0; |
|
79 |
double landa = alfa/2.0; |
|
80 |
dd = (d/2.0)/(Math.tan(landa)); |
|
81 |
radio = (d/2.0)/(Math.sin(landa)); |
|
82 |
aci = Math.atan((coord2[0]-coord1[0])/(coord2[1]-coord1[1])); |
|
83 |
double aciDegree = aci*180.0/Math.PI; |
|
84 |
if (coord2[1] > coord1[1]) { |
|
85 |
aci += Math.PI; |
|
86 |
aciDegree = aci*180.0/Math.PI; |
|
87 |
} |
|
88 |
center = new double[]{coordAux[0] + dd*Math.sin(aci+(Math.PI/2.0)), coordAux[1] + dd*Math.cos(aci+(Math.PI/2.0))}; |
|
89 |
calEA(alfa); |
|
90 |
} |
|
91 |
|
|
92 |
private void calEA(double alfa){ |
|
93 |
empieza = Math.atan2(coord1[1]-center[1], coord1[0]-center[0]); |
|
94 |
acaba = (empieza + alfa); |
|
95 |
empieza = empieza*180.0/Math.PI; |
|
96 |
acaba = acaba*180.0/Math.PI; |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* This method calculates an arc in a Gis geometry model. This arc is represented in |
|
101 |
* this model by a Vector of Point2D. The distance between points in the arc is given |
|
102 |
* as an argument |
|
103 |
* |
|
104 |
* @param inc Distance between points in the arc |
|
105 |
* @return Vector Vector with the set of Point2D that represents the arc |
|
106 |
*/ |
|
107 |
public Vector getPoints(double inc) { |
|
108 |
Vector arc = new Vector(); |
|
109 |
double angulo; |
|
110 |
int iempieza = (int) empieza + 1; |
|
111 |
int iacaba = (int) acaba; |
|
112 |
if (empieza <= acaba) { |
|
113 |
addNode(arc, empieza); |
|
114 |
for (angulo = iempieza; angulo <= iacaba; angulo += inc) { |
|
115 |
addNode(arc, angulo); |
|
116 |
} |
|
117 |
addNode(arc, acaba); |
|
118 |
} else { |
|
119 |
addNode(arc, empieza); |
|
120 |
for (angulo = iempieza ; angulo <= 360; angulo += inc) { |
|
121 |
addNode(arc, angulo); |
|
122 |
} |
|
123 |
for (angulo = 1; angulo <= iacaba; angulo += inc) { |
|
124 |
addNode(arc, angulo); |
|
125 |
} |
|
126 |
addNode(arc, angulo); |
|
127 |
} |
|
128 |
Point2D aux = (Point2D)arc.get(arc.size()-1); |
|
129 |
double aux1 = Math.abs(aux.getX()-coord2[0]); |
|
130 |
double aux2 = Math.abs(aux.getY()-coord2[1]); |
|
131 |
return arc; |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Method that allows to obtain a set of points located in the central zone of |
|
136 |
* this arc object |
|
137 |
*/ |
|
138 |
public Vector getCentralPoint() { |
|
139 |
Vector arc = new Vector(); |
|
140 |
if (empieza <= acaba) { |
|
141 |
addNode(arc, (empieza+acaba)/2.0); |
|
142 |
} else { |
|
143 |
addNode(arc, empieza); |
|
144 |
double alfa = 360-empieza; |
|
145 |
double beta = acaba; |
|
146 |
double an = alfa + beta; |
|
147 |
double mid = an/2.0; |
|
148 |
if (mid<=alfa) { |
|
149 |
addNode(arc, empieza+mid); |
|
150 |
} else { |
|
151 |
addNode(arc, mid-alfa); |
|
152 |
} |
|
153 |
} |
|
154 |
return arc; |
|
155 |
} |
|
156 |
|
|
157 |
private void addNode(Vector arc, double angulo) { |
|
158 |
double yy = center[1] + radio * Math.sin(angulo*Math.PI/180.0); |
|
159 |
double xx = center[0] + radio * Math.cos(angulo*Math.PI/180.0); |
|
160 |
arc.add(new Point2D.Double(xx,yy)); |
|
161 |
} |
|
162 |
} |
|
0 | 163 |
tags/v2_0_0_Build_2056/libraries/libDwg/src/org/gvsig/dwg/lib/util/GisModelCurveCalculator.java | ||
---|---|---|
1 |
/* jdwglib. Java Library for reading Dwg files. |
|
2 |
* |
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com). |
|
4 |
* Port from the Pythoncad Dwg library by Art Haas. |
|
5 |
* |
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. and Generalitat Valenciana |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Jose Morell (jose.morell@gmail.com) |
|
25 |
* |
|
26 |
* or |
|
27 |
* |
|
28 |
* IVER TI S.A. |
|
29 |
* C/Salamanca, 50 |
|
30 |
* 46005 Valencia |
|
31 |
* Spain |
|
32 |
* +34 963163400 |
|
33 |
* dac@iver.es |
|
34 |
*/ |
|
35 |
package org.gvsig.dwg.lib.util; |
|
36 |
|
|
37 |
import java.awt.geom.Point2D; |
|
38 |
import java.util.ArrayList; |
|
39 |
import java.util.List; |
|
40 |
import java.util.Vector; |
|
41 |
|
|
42 |
/** |
|
43 |
* This class allows to obtain arcs and circles given by the most usual parameters, in a |
|
44 |
* Gis geometry model. In this model, an arc or a circle is given by a set of points that |
|
45 |
* defines it shape |
|
46 |
* |
|
47 |
* @author jmorell |
|
48 |
*/ |
|
49 |
public class GisModelCurveCalculator { |
|
50 |
|
|
51 |
/** |
|
52 |
* This method calculates an array of Point2D that represents a circle. The distance |
|
53 |
* between it points is 1 angular unit |
|
54 |
* |
|
55 |
* @param c Point2D that represents the center of the circle |
|
56 |
* @param r double value that represents the radius of the circle |
|
57 |
* @return Point2D[] An array of Point2D that represents the shape of the circle |
|
58 |
*/ |
|
59 |
public static List calculateGisModelCircle(Point2D c, double r) { |
|
60 |
List pts = new ArrayList(); |
|
61 |
int angulo = 0; |
|
62 |
for (angulo=0; angulo<360; angulo++) { |
|
63 |
double[] pt = new double[]{c.getX(), c.getY()}; |
|
64 |
pt[0] = pt[0] + r * Math.sin(angulo*Math.PI/(double)180.0); |
|
65 |
pt[1] = pt[1] + r * Math.cos(angulo*Math.PI/(double)180.0); |
|
66 |
|
|
67 |
pts.add(pt); |
|
68 |
} |
|
69 |
return pts; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* This method calculates an array of Point2D that represents a ellipse. The distance |
|
74 |
* between it points is 1 angular unit |
|
75 |
* |
|
76 |
* @param center Point2D that represents the center of the ellipse |
|
77 |
* @param majorAxisVector Point2D that represents the vector for the major axis |
|
78 |
* @param axisRatio double value that represents the axis ratio |
|
79 |
* @param initAngle double value that represents the start angle of the ellipse arc |
|
80 |
* @param endAngle double value that represents the end angle of the ellipse arc |
|
81 |
* @return Point2D[] An array of Point2D that represents the shape of the ellipse |
|
82 |
*/ |
|
83 |
public static List calculateGisModelEllipse(Point2D center, Point2D majorAxisVector, double axisRatio, double initAngle, double endAngle) { |
|
84 |
Point2D majorPoint = new Point2D.Double(center.getX()+majorAxisVector.getX(), center.getY()+majorAxisVector.getY()); |
|
85 |
double orientation = Math.atan(majorAxisVector.getY()/majorAxisVector.getX()); |
|
86 |
double semiMajorAxisLength = center.distance(majorPoint); |
|
87 |
double semiMinorAxisLength = semiMajorAxisLength*axisRatio; |
|
88 |
double eccentricity = Math.sqrt(1-((Math.pow(semiMinorAxisLength, 2))/(Math.pow(semiMajorAxisLength, 2)))); |
|
89 |
int isa = (int)initAngle; |
|
90 |
int iea = (int)endAngle; |
|
91 |
double angulo; |
|
92 |
List pts = new ArrayList(); |
|
93 |
if (initAngle <= endAngle) { |
|
94 |
angulo = initAngle; |
|
95 |
double r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2)))); |
|
96 |
double x = r*Math.cos(angulo*Math.PI/(double)180.0); |
|
97 |
double y = r*Math.sin(angulo*Math.PI/(double)180.0); |
|
98 |
double xrot = x*Math.cos(orientation) - y*Math.sin(orientation); |
|
99 |
double yrot = x*Math.sin(orientation) + y*Math.cos(orientation); |
|
100 |
|
|
101 |
double[] pt = new double[]{center.getX() + xrot, center.getY() + yrot }; |
|
102 |
pts.add(pt); |
|
103 |
|
|
104 |
for (int i=1; i<=(iea-isa)+1; i++) { |
|
105 |
angulo = (double)(isa+i); |
|
106 |
r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2)))); |
|
107 |
x = r*Math.cos(angulo*Math.PI/(double)180.0); |
|
108 |
y = r*Math.sin(angulo*Math.PI/(double)180.0); |
|
109 |
xrot = x*Math.cos(orientation) - y*Math.sin(orientation); |
|
110 |
yrot = x*Math.sin(orientation) + y*Math.cos(orientation); |
|
111 |
|
|
112 |
pt = new double[]{center.getX() + xrot, center.getY() + yrot}; |
|
113 |
pts.add(pt); |
|
114 |
} |
|
115 |
|
|
116 |
angulo = endAngle; |
|
117 |
r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2)))); |
|
118 |
x = r*Math.cos(angulo*Math.PI/(double)180.0); |
|
119 |
y = r*Math.sin(angulo*Math.PI/(double)180.0); |
|
120 |
xrot = x*Math.cos(orientation) - y*Math.sin(orientation); |
|
121 |
yrot = x*Math.sin(orientation) + y*Math.cos(orientation); |
|
122 |
|
|
123 |
|
|
124 |
pt = new double[]{center.getX() + xrot, center.getY() + yrot}; |
|
125 |
pts.add(pt); |
|
126 |
|
|
127 |
} else { |
|
128 |
angulo = initAngle; |
|
129 |
double r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2)))); |
|
130 |
double x = r*Math.cos(angulo*Math.PI/(double)180.0); |
|
131 |
double y = r*Math.sin(angulo*Math.PI/(double)180.0); |
|
132 |
double xrot = x*Math.cos(orientation) - y*Math.sin(orientation); |
|
133 |
double yrot = x*Math.sin(orientation) + y*Math.cos(orientation); |
|
134 |
|
|
135 |
|
|
136 |
double[] pt = new double[]{center.getX() + r*Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r*Math.sin(angulo*Math.PI/(double)180.0)}; |
|
137 |
pts.add(pt); |
|
138 |
|
|
139 |
for (int i=1; i<=(360-isa); i++) { |
|
140 |
angulo = (double)(isa+i); |
|
141 |
r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2)))); |
|
142 |
x = r*Math.cos(angulo*Math.PI/(double)180.0); |
|
143 |
y = r*Math.sin(angulo*Math.PI/(double)180.0); |
|
144 |
xrot = x*Math.cos(orientation) - y*Math.sin(orientation); |
|
145 |
yrot = x*Math.sin(orientation) + y*Math.cos(orientation); |
|
146 |
|
|
147 |
pt = new double[]{center.getX() + xrot, center.getY() + yrot}; |
|
148 |
pts.add(pt); |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) { |
|
153 |
angulo = (double)(i-(360-isa)); |
|
154 |
r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2)))); |
|
155 |
x = r*Math.cos(angulo*Math.PI/(double)180.0); |
|
156 |
y = r*Math.sin(angulo*Math.PI/(double)180.0); |
|
157 |
xrot = x*Math.cos(orientation) - y*Math.sin(orientation); |
|
158 |
yrot = x*Math.sin(orientation) + y*Math.cos(orientation); |
|
159 |
|
|
160 |
pt = new double[]{center.getX() + xrot, center.getY() + yrot}; |
|
161 |
pts.add(pt); |
|
162 |
|
|
163 |
} |
|
164 |
|
|
165 |
angulo = endAngle; |
|
166 |
r = semiMinorAxisLength/Math.sqrt(1-((Math.pow(eccentricity, 2))*(Math.pow(Math.cos(angulo*Math.PI/(double)180.0), 2)))); |
|
167 |
x = r*Math.cos(angulo*Math.PI/(double)180.0); |
|
168 |
y = r*Math.sin(angulo*Math.PI/(double)180.0); |
|
169 |
xrot = x*Math.cos(orientation) - y*Math.sin(orientation); |
|
170 |
yrot = x*Math.sin(orientation) + y*Math.cos(orientation); |
|
171 |
|
|
172 |
pt = new double[]{center.getX() + xrot, center.getY() + yrot}; |
|
173 |
pts.add(pt); |
|
174 |
} |
|
175 |
return pts; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* This method calculates an array of Point2D that represents an arc. The distance |
|
180 |
* between it points is 1 angular unit |
|
181 |
* |
|
182 |
* @param c Point2D that represents the center of the arc |
|
183 |
* @param r double value that represents the radius of the arc |
|
184 |
* @param sa double value that represents the start angle of the arc |
|
185 |
* @param ea double value that represents the end angle of the arc |
|
186 |
* @return Point2D[] An array of Point2D that represents the shape of the arc |
|
187 |
*/ |
|
188 |
public static List calculateGisModelArc(double[] center, double r, double sa, double ea) { |
|
189 |
int isa = (int)sa; |
|
190 |
int iea = (int)ea; |
|
191 |
double angulo; |
|
192 |
List pts = new ArrayList(); |
|
193 |
if (sa <= ea) { |
|
194 |
angulo = sa; |
|
195 |
pts.add(new double[]{center[0] + r * Math.cos(angulo*Math.PI/(double)180.0), |
|
196 |
center[1] + r * Math.sin(angulo*Math.PI/(double)180.0)}); |
|
197 |
for (int i=1; i <= (iea-isa)+1; i++) { |
|
198 |
angulo = (double)(isa+i); |
|
199 |
double x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0); |
|
200 |
double y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0); |
|
201 |
pts.add(new double[]{x, y}); |
|
202 |
} |
|
203 |
angulo = ea; |
|
204 |
double x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0); |
|
205 |
double y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0); |
|
206 |
pts.add(new double[]{x, y}); |
|
207 |
} else { |
|
208 |
angulo = sa; |
|
209 |
double x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0); |
|
210 |
double y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0); |
|
211 |
pts.add(new double[]{x, y}); |
|
212 |
for (int i=1; i <= (360-isa); i++) { |
|
213 |
angulo = (double)(isa+i); |
|
214 |
x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0); |
|
215 |
y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0); |
|
216 |
pts.add(new double[]{x, y}); |
|
217 |
} |
|
218 |
|
|
219 |
for (int i=( 360-isa)+1; i <= (360-isa)+iea; i++) { |
|
220 |
angulo = (double)(i-(360-isa)); |
|
221 |
x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0); |
|
222 |
y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0); |
|
223 |
pts.add(new double[]{x, y}); |
|
224 |
} |
|
225 |
angulo = ea; |
|
226 |
x = center[0] + r * Math.cos(angulo*Math.PI/(double)180.0); |
|
227 |
y = center[1] + r * Math.sin(angulo*Math.PI/(double)180.0); |
|
228 |
pts.add(new double[]{x, y}); |
|
229 |
} |
|
230 |
return pts; |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* This method applies an array of bulges to an array of Point2D that defines a |
|
235 |
* polyline. The result is a polyline with the input points with the addition of the |
|
236 |
* points that define the new arcs added to the polyline |
|
237 |
* |
|
238 |
* @param newPts Base points of the polyline |
|
239 |
* @param bulges Array of bulge parameters |
|
240 |
* @return Polyline with a new set of arcs added and defined by the bulge parameters |
|
241 |
*/ |
Also available in: Unified diff