Sei sulla pagina 1di 35

Libro de Trabajo

Satelite Básico
java3D

Prof. Andrés E. Castillo R.
EL
EL programa D
Demo Satelite
S t lit está
tá compuesto
t de:
d
• Ventana que extends de JFrame.
• Escena Grafica conformada por un SimpleUniverse.
• Rama Geometrica
Rama Geometrica conformada por un objeto
un objeto Satelite.

Satelite a su vez es un objeto que se basa en una caja y


en unas alas , que se derivan de Box, un eje que se
deriva de Cylinder, ademas tiene unos elemento
Paraboloide, Conoide y Patron1, que sirven para
conforman las antenas del satelite.

Otro aspecto muy importante, es que el objeto Sate‐


lite, viene con una serie de funciones, métodos, tales
como girar según los ejes,
ejes girar las alas (paneles foto
foto‐
electricos) y volver transparente el cuerpo principal.

Este programa ilustra, la utilidad de trabajar


con objetos.
Ventana Básica
DemoSatelite.java 31/01/2009 09:29 p.m.

1 import javax.swing.*;
2 class DemoSatelite extends JFrame
3 {
4 DemoSatelite()
5 {
6 super("Demo Satelite");
7 EscenaGraficaSatelite eg = new EscenaGraficaSatelite();
8 setSize(700,500);
9 setLocation(200,200);
10 getContentPane().add("Center",eg.getCanvas3D());
11 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12 setVisible(true);
13 }
14 public static void main(String[] args)
15 {
16 DemoSatelite demo = new DemoSatelite();
17 }
18 }
19

Page 1 of 1
Escena Grafica
EscenaGraficaSatelite.java 31/01/2009 09:29 p.m.

1 import javax.media.j3d.*;
2 import com.sun.j3d.utils.universe.*;
3 import com.sun.j3d.utils.geometry.*;
4 import javax.vecmath.*;
5 import java.awt.*;
6
7
8 class EscenaGraficaSatelite
9 {
10 Canvas3D canvas3D;
11 EscenaGraficaSatelite()
12 {
13 GraphicsConfiguration config = SimpleUniverse.getPreferredConfig
14 canvas3D = new Canvas3D(config);
15 SimpleUniverse su = new SimpleUniverse(canvas3D);
16 double x,y,z;
17 double r,phi,tetha;
18 r = 25.0;
19 phi = 60.0;
20 tetha =35.0;
21 x = r*Math.cos(Math.toRadians(tetha))*Math.sin(Math.toRadians(ph
22 y = r*Math.cos(Math.toRadians(tetha))*Math.cos(Math.toRadians(ph
23 z = r*Math.sin(Math.toRadians(tetha));
24 Transform3D t3d = new Transform3D();
25 t3d.lookAt( new Point3d(x,y,z),new Point3d(0.0,0.0,0.0), new Vec
26 t3d.invert();
27 su.getViewingPlatform().getViewPlatformTransform().setTransform(
28 BranchGroup bg = new BranchGroup();
29 Satelite satelite = new Satelite();
30 satelite.rotarEjeY(45);
31 satelite.rotarEjeZ(45);
32 bg.addChild(satelite);
33 bg.compile();
34 su.addBranchGraph(bg);
35 }
36 public Canvas3D getCanvas3D()
37 {
38 return canvas3D;
39 }
40 }
41

Page 1 of 1
Satelite
Satelite.java 31/01/2009 09:27 p.m.

1 import java.awt.*;
2 import javax.swing.*;
3 import javax.media.j3d.*;
4 import javax.vecmath.*;
5 import com.sun.j3d.utils.geometry.*;
6 import com.sun.j3d.utils.universe.*;
7 import com.sun.j3d.utils.behaviors.keyboard.*;
8
9 public class Satelite extends BranchGroup
10 {
11
12 private float x,y,z;
13 private TransformGroup rotacionAlas,rotacionCilindro;
14 private TransformGroup rotacion;
15 private TransformGroup traslacionSatelite;
16 private TransformGroup traslacionAla1,traslacionAla2;
17 private Patron1 patronAnt1,patronAnt2,patronAnt3;
18 private Conoide conoAnt1,conoAnt2,conoAnt3;
19 private Paraboloide paraboloide1,paraboloide2,paraboloide3;
20 private TransformGroup traslacionParaboloide1,traslacionParaboloide
21 private TransformGroup cambiarTamaño;
22 private BranchGroup sat;
23 private Transform3D rot ;
24 private double refZ,refX,refY;
25 private Transform3D utility,utility2,utility3,utility4,utility5,uti
26 private TransparencyAttributes ta;
27 public Satelite()
28 {
29 //Paraboloides
30 utility = new Transform3D();
31 utility2 = new Transform3D();
32 utility3 = new Transform3D();
33 utility4 = new Transform3D();
34 utility5 = new Transform3D();
35 utility6 = new Transform3D();
36 traslacionParaboloide1 = new TransformGroup();
37 traslacionParaboloide2 = new TransformGroup();
38 traslacionParaboloide3 = new TransformGroup();
39 paraboloide1 = new Paraboloide(1.0,0.35,100,100);
40 paraboloide2 = new Paraboloide(1.0,0.35,100,100);
41 paraboloide3 = new Paraboloide(1.0,0.35,100,100);
42 patronAnt1 = new Patron1(8.0,7,7,100,100,1.0f);
43 patronAnt2 = new Patron1(8.0,7,7,100,100,1.0f);
44 patronAnt3 = new Patron1(8.0,7,7,100,100,1.0f);
45 conoAnt1 = new Conoide(12.0f,10.0f,5,180,0.7f);
46 conoAnt2 = new Conoide(12.0f,10.0f,5,180,0.7f);
47 conoAnt3 = new Conoide(12.0f,10.0f,5,180,0.7f);
48 traslacionParaboloide1.addChild(paraboloide1);
49 traslacionParaboloide2.addChild(paraboloide2);
50 traslacionParaboloide3.addChild(paraboloide3);
51 traslacionParaboloide1.addChild(patronAnt1);

Page 1 of 8
Satelite.java 31/01/2009 09:27 p.m.

52 traslacionParaboloide2.addChild(patronAnt2);
53 traslacionParaboloide3.addChild(patronAnt3);
54 traslacionParaboloide1.addChild(conoAnt1);
55 traslacionParaboloide2.addChild(conoAnt2);
56 traslacionParaboloide3.addChild(conoAnt3);
57
58
59 Transform3D traslacionP1 = new Transform3D();
60 traslacionP1.setTranslation(new Vector3f(0.0f,0.0f,0.6f));
61 traslacionParaboloide1.setTransform(traslacionP1);
62 Transform3D traslacionP2 = new Transform3D();
63 traslacionP2.setTranslation(new Vector3f(0.0f,1.20f,-0.5f));
64 traslacionParaboloide2.setTransform(traslacionP2);
65 Transform3D traslacionP3 = new Transform3D();
66 traslacionP3.setTranslation(new Vector3f(0.0f,-1.20f,-0.5f));
67 traslacionParaboloide3.setTransform(traslacionP3);
68 rot = new Transform3D();
69 rotacion = new TransformGroup();
70 refZ = 0.0;
71 refX = 0.0;
72 refY = 0.0;
73 float r = 1.0f;
74 float tetha = 90.0f;
75 float phi = 0.0f;
76 this.x =r*(float)(Math.sin(tetha*Math.PI/180.0)*Math.cos(phi*Ma
77 this.y =r*(float)(Math.sin(tetha*Math.PI/180.0)*Math.sin(phi*Ma
78 this.z =r*(float)(Math.cos(tetha*Math.PI/180));
79
80 traslacionSatelite = new TransformGroup();
81 moverSatelite(this.x,this.y,this.z);
82 rotacionAlas = new TransformGroup();
83 traslacionAla1 = new TransformGroup();
84 traslacionAla2 = new TransformGroup();
85 cambiarTamaño = new TransformGroup();
86
87 rotacionAlas.setCapability(TransformGroup.ALLOW_TRANSFORM_READ)
88 rotacionAlas.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE
89 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
90 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
91 traslacionSatelite.setCapability(TransformGroup.ALLOW_TRANSFORM
92 traslacionSatelite.setCapability(TransformGroup.ALLOW_TRANSFORM
93 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_READ
94 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_WRIT
95 com.sun.j3d.utils.geometry.Box caja =
96 new com.sun.j3d.utils.geometry.Box(0.5f,
97 0.5f,0.
98 Appearance colorCaja = new Appearance();
99 colorCaja.setColoringAttributes(new ColoringAttributes(1.0f,0.0
100 ColoringAttributes.SHADE_G
101
102

Page 2 of 8
Satelite.java 31/01/2009 09:27 p.m.

103 ta = new TransparencyAttributes(TransparencyAttributes.SCREEN_D


104 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
105 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
106 colorCaja.setTransparencyAttributes(ta);
107 caja.setAppearance(colorCaja);
108
109 com.sun.j3d.utils.geometry.Box ala1 =
110 new com.sun.j3d.utils.geometry.Box(3.0f,
111 0.45f,0.01f,null);
112 com.sun.j3d.utils.geometry.Box ala2 =
113 new com.sun.j3d.utils.geometry.Box(3.0f,
114 0.45f,0.01f,null);
115 Appearance colorAlas = new Appearance();
116 colorAlas.setColoringAttributes(new ColoringAttributes(0.0f,0.0
117 ColoringAttributes.SHADE_G
118 ala1.setAppearance(colorAlas);
119 ala2.setAppearance(colorAlas);
120
121 Transform3D traslacion1 = new Transform3D();
122 traslacion1.setTranslation(new Vector3f(3.70f,0.0f,0.0f));
123 traslacionAla1.setTransform(traslacion1);
124
125 Transform3D traslacion2 = new Transform3D();
126 traslacion2.setTranslation(new Vector3f(-3.70f,0.0f,0.0f));
127 traslacionAla2.setTransform(traslacion2);
128 com.sun.j3d.utils.geometry.Cylinder cilindro =
129 new com.sun.j3d.utils.geometry.Cylinder(0.05f,
130 2.5f,null);
131 rotacionCilindro = new TransformGroup();
132 Transform3D rotacionCilindroEjeZ = new Transform3D();
133 rotacionCilindroEjeZ.rotZ(Math.PI/2);
134 rotacionCilindro.setTransform(rotacionCilindroEjeZ);
135 rotacionCilindro.addChild(cilindro);
136 Appearance colorCilindro = new Appearance();
137 colorCilindro.setColoringAttributes(new ColoringAttributes(1.0f
138 ColoringAttributes.SHADE_G
139 cilindro.setAppearance(colorCilindro);
140 sat = new BranchGroup();
141 this.addChild(traslacionSatelite);
142 traslacionSatelite.addChild(rotacion);
143 rotacion.addChild(cambiarTamaño);
144 cambiarTamaño.addChild(sat);
145 sat.addChild(rotacionAlas);
146 traslacionAla1.addChild(ala1);
147 traslacionAla2.addChild(ala2);
148 rotacionAlas.addChild(traslacionAla1);
149 rotacionAlas.addChild(traslacionAla2);
150
151 sat.addChild(caja);
152 sat.addChild(rotacionCilindro);
153 LineArray ejeY = new LineArray(2,LineArray.COORDINATES);

Page 3 of 8
Satelite.java 31/01/2009 09:27 p.m.

154 LineArray ejeX = new LineArray(2,LineArray.COORDINATES);


155 LineArray ejeZ = new LineArray(2,LineArray.COORDINATES);
156
157 ejeY.setCoordinate(0,new Point3f(0.0f,-5.0f,0.0f));
158 ejeY.setCoordinate(1,new Point3f(0.0f,5.0f,0.0f));
159 //sat.addChild( new Shape3D(ejeY));
160
161 ejeX.setCoordinate(0,new Point3f(-5.0f,0.0f,0.0f));
162 ejeX.setCoordinate(1,new Point3f(5f,0.0f,0.0f));
163 //sat.addChild( new Shape3D(ejeX));
164 sat.addChild(traslacionParaboloide1);
165 sat.addChild(traslacionParaboloide2);
166 sat.addChild(traslacionParaboloide3);
167 ejeZ.setCoordinate(0,new Point3f(0.0f,0.0f,-3.0f));
168 ejeZ.setCoordinate(1,new Point3f(0,0.0f,3.0f));
169 //sat.addChild( new Shape3D(ejeZ));
170
171 //this.addChild( new Shape3D(ejeZ));
172 //this.addChild( new Shape3D(ejeY));
173 //this.addChild( new Shape3D(ejeZ));
174
175 this.compile();
176 }
177
178 public void moverSatelite(float x, float y, float z)
179 {
180 this.x = x;
181 this.y = y;
182 this.z = z;
183
184 //Transform3D traslacion = new Transform3D();
185 //traslacion.setTranslation(new Vector3f(x,y,z));
186 //traslacionSatelite.setTransform(traslacion);
187 utility.setTranslation(new Vector3f(x,y,z));
188 traslacionSatelite.setTransform(utility);
189 }
190 public void rotarEjeZ(double giroEjeZ)
191 {
192 //Transform3D rotacionZ = new Transform3D();
193 //rotacionZ.rotZ((giroEjeZ-refZ)*Math.PI/180.0d);
194 //rot.mul(rotacionZ);
195 //this.rotacion.setTransform(rot);
196 utility2.rotZ((giroEjeZ-refZ)*Math.PI/180.0d);
197 rot.mul(utility2);
198 this.rotacion.setTransform(rot);
199 refZ = giroEjeZ;
200 }
201
202 public void rotarEjeY(double giroEjeY)
203 {
204 //Transform3D rotacionY = new Transform3D();

Page 4 of 8
Satelite.java 31/01/2009 09:27 p.m.

205 //rotacionY.rotY((giroEjeY-refY)*Math.PI/180.0d);
206 //rot.mul(rotacionY);
207 //Transform3D rotacionY = new Transform3D();
208 utility3.rotY((giroEjeY-refY)*Math.PI/180.0d);
209 rot.mul(utility3);
210 this.rotacion.setTransform(rot);
211 refY = giroEjeY;
212 }
213
214 public void rotarEjeX(double giroEjeX)
215 {
216 //Transform3D rotacionX = new Transform3D();
217 //rotacionX.rotX((giroEjeX-refX)*Math.PI/180.0d);
218 //rot.mul(rotacionX);
219 utility4.rotX((giroEjeX-refX)*Math.PI/180.0d);
220 rot.mul(utility4);
221 this.rotacion.setTransform(rot);
222 refX = giroEjeX;
223 }
224
225 public void rotarAlas(double giroAlas)
226 {
227 //Transform3D rotacion = new Transform3D();
228 //rotacion.rotX(giroAlas*Math.PI/180.0d);
229 //Transform3D rotacion = new Transform3D();
230 utility5.rotX(giroAlas*Math.PI/180.0d);
231 this.rotacionAlas.setTransform(utility5);
232 }
233 public void escalar(double tamaño)
234 {
235 //Transform3D cambioTamaño = new Transform3D();
236 //cambioTamaño.setScale(tamaño);
237 utility6.setScale(tamaño);
238 cambiarTamaño.setTransform(utility6);
239 }
240 public void setX(float x)
241 {
242 this.x = x;
243 moverSatelite(this.x, this.y, this.z);
244
245 }
246 public void setY(float y)
247 {
248 this.y = y;
249 moverSatelite(this.x, this.y, this.z);
250
251 }
252 public void setZ(float z)
253 {
254 this.z = z;
255 moverSatelite(this.x, this.y, this.z);

Page 5 of 8
Satelite.java 31/01/2009 09:27 p.m.

256 }
257 public double getX()
258 {
259 return this.x;
260 }
261 public double getY()
262 {
263 return this.y;
264 }
265 public double getZ()
266 {
267 return this.z;
268 }
269 public float getR()
270 {
271 return (float) Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2)+
272 }
273 public float getPhi()
274 {
275 float aux = 0.0f;
276 if(this.x == 0)
277 {
278 if(this.y >= 0)
279 {
280 aux = 90.0f;
281 }
282 else
283 {
284 aux = 270.0f;
285 }
286 }
287 if(this.x > 0)
288 {
289 if(this.y>=0)
290 {
291
292 aux = (float) ( Math.atan(Math.abs(this.y/this.x))*180.
293 System.out.println("Llamaron a getPhi() cuadro I: " +
294 }
295 else
296 {
297 aux = 360.0f-(float) ( Math.atan(Math.abs(this.y/this.x
298 System.out.println("Llamaron a getPhi() cuadro IV: " +
299 }
300 }
301 if(this.x < 0)
302 {
303 if(this.y>=0)
304 {
305 aux = 180.0f-(float) ( Math.atan(Math.abs(this.y/this.x
306 System.out.println("Llamaron a getPhi() cuadro II: " +

Page 6 of 8
Satelite.java 31/01/2009 09:27 p.m.

307 }
308 else
309 {
310 aux = 180.0f+(float) ( Math.atan(Math.abs(this.y/this.x
311 System.out.println("Llamaron a getPhi() cuadro III: "
312 }
313 }
314
315 return aux;
316
317 }
318 public float getTetha()
319 {
320 return (float) ( Math.acos(this.z/getR())*180.0/Math.PI);
321 }
322 public void set_R_Phi_Tetha(float r, float phi, float tetha)
323 {
324 this.x =r*(float)(Math.sin(Math.toRadians(tetha))*Math.cos(Math
325 this.y =r*(float)(Math.sin(Math.toRadians(tetha))*Math.sin(Math
326 this.z =r*(float)(Math.cos(Math.toRadians(tetha)));
327 moverSatelite(this.x, this.y, this.z);
328 }
329 public void setR(float r)
330 {
331 set_R_Phi_Tetha(r,getPhi(),getTetha());
332 }
333 public void setPhi(float phi)
334 {
335 set_R_Phi_Tetha(getR(),phi,getTetha());
336 }
337 public void setTetha(float tetha)
338 {
339 set_R_Phi_Tetha(getR(),getPhi(),tetha);
340 }
341
342 public Paraboloide getParaboloide1()
343 {
344 return paraboloide1;
345 }
346
347 public Paraboloide getParaboloide2()
348 {
349 return paraboloide2;
350 }
351
352 public Paraboloide getParaboloide3()
353 {
354 return paraboloide3;
355 }
356 public Patron1 getPatronAnt1()
357 {

Page 7 of 8
Satelite.java 31/01/2009 09:27 p.m.

358 return patronAnt1;


359 }
360 public Patron1 getPatronAnt2()
361 {
362 return patronAnt2;
363 }
364 public Patron1 getPatronAnt3()
365 {
366 return patronAnt3;
367 }
368 public Conoide getCono1()
369 {
370 return conoAnt1;
371 }
372 public Conoide getCono2()
373 {
374 return conoAnt2;
375 }
376 public Conoide getCono3()
377 {
378 return conoAnt3;
379 }
380 public void ajustarTransparencia(float transparencia)
381 {
382 ta.setTransparency(transparencia);
383 }
384 }
385
386
387

Page 8 of 8
Paraboloide
Paraboloide.java 31/01/2009 09:27 p.m.

1 import javax.media.j3d.*;
2 import javax.vecmath.*;
3
4 public class Paraboloide extends BranchGroup
5 {
6 double diametro, rfd, giroX,giroY,giroZ,giroPlato,x,y,z;
7 int n,m;
8 TransformGroup rotacion,traslacion,cambiarTamaño,girarPlato;
9 Transform3D rot,rotarPlato,utility;
10
11 public Paraboloide(double diametro, double rfd, int n , int m)
12 {
13 utility = new Transform3D();
14 rot = new Transform3D();
15 girarPlato = new TransformGroup();
16 rotarPlato = new Transform3D();
17 girarPlato.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
18 girarPlato.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
19 this.x = 0.0;
20 this.y = 0.0;
21 this.z = 0.0;
22 giroX = 0.0;
23 giroY = 0.0;
24 giroZ = 0.0;
25 giroPlato = 0.0;
26 this.diametro = diametro;
27 this.rfd = rfd;
28 this.m = m;
29 this.n = n;
30 int[] verticeporTiras = new int[n];
31 int formato = TriangleStripArray.COORDINATES | TriangleStripArr
32 Point3d punto = new Point3d();
33 double posX,posY,posZ;
34 double deltaPhi = 360.0/(this.n-1);
35 double deltaRho = this.diametro/(2*(m-1));
36 double foco = rfd*this.diametro;
37 Color3f amarillo = new Color3f(0.7f,1.7f,0.7f);
38 Color3f verde = new Color3f(0.4f,0.4f,0.4f);
39 for (int s = 0;s < n ;s++ )
40 {
41 verticeporTiras[s] = 2*m;
42 }
43 TriangleStripArray geoPar1 = new TriangleStripArray(2*m*n,forma
44 TriangleStripArray geoPar2 = new TriangleStripArray(2*m*n,forma
45
46 for (int i = 0; i < n ;i++ )
47 for (int j = 0; j<m ;j++ )
48 for(int k = 0; k<2;k++)
49
50 {
51 posX = (j*deltaRho)*Math.cos((i+k)*deltaPhi*Math.PI/180.0);

Page 1 of 4
Paraboloide.java 31/01/2009 09:27 p.m.

52 posY = (j*deltaRho)*Math.sin((i+k)*deltaPhi*Math.PI/180.0);
53 posZ =(Math.pow(posX,2)+Math.pow(posY,2))/(4*foco);
54 punto = new Point3d(posX,posY,posZ);
55 geoPar1.setCoordinate(i*2*m+2*j+k,punto);
56 geoPar1.setColor(i*2*m+2*j+k,verde);
57 }
58
59 for (int i = 0; i < n ;i++ )
60 for (int j = 0; j<m ;j++ )
61 for(int k = 0; k<2;k++)
62
63 {
64 posX = (j*deltaRho)*Math.cos((i+k)*deltaPhi*Math.PI/180.0);
65 posY = (j*deltaRho)*Math.sin((i+k)*deltaPhi*Math.PI/180.0);
66 posZ =(Math.pow(posX,2)+Math.pow(posY,2))/(4*foco);
67 punto = new Point3d(posX,posY,posZ);
68 geoPar2.setCoordinate(i*2*m+2*j+k,punto);
69 geoPar2.setColor(i*2*m+2*j+k,amarillo);
70 }
71
72 PolygonAttributes apPoly = new PolygonAttributes();
73 apPoly.setCullFace(PolygonAttributes.CULL_NONE);
74 Appearance dosCaras = new Appearance();
75 dosCaras.setPolygonAttributes(apPoly);
76
77 PolygonAttributes apPol1 = new PolygonAttributes();
78 apPol1.setCullFace(PolygonAttributes.CULL_BACK);
79 Appearance caraAnterior = new Appearance();
80 caraAnterior.setPolygonAttributes(apPol1);
81
82 PolygonAttributes apPol2 = new PolygonAttributes();
83 apPol2.setCullFace(PolygonAttributes.CULL_FRONT);
84 Appearance caraPosterior= new Appearance();
85 caraPosterior.setPolygonAttributes(apPol2);
86
87 Shape3D parabolica1 = new Shape3D(geoPar1,caraPosterior);
88 Shape3D parabolica2 = new Shape3D(geoPar2,caraAnterior);
89 rotacion = new TransformGroup();
90 traslacion = new TransformGroup();
91 cambiarTamaño = new TransformGroup();
92 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
93 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
94 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
95 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
96 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_WRIT
97 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_READ
98 BranchGroup parabolica = new BranchGroup();
99 parabolica.addChild(parabolica1);
100 parabolica.addChild(parabolica2);
101 girarPlato.addChild(parabolica);
102 rotacion.addChild(girarPlato);

Page 2 of 4
Paraboloide.java 31/01/2009 09:27 p.m.

103 traslacion.addChild(rotacion);
104 LineArray ejeZ = new LineArray(2,LineArray.COORDINATES);
105 ejeZ.setCoordinate(0,new Point3f(0.0f,0.0f,-3.0f));
106 ejeZ.setCoordinate(1,new Point3f(0.0f,0.0f,3.0f));
107 LineArray ejeY = new LineArray(2,LineArray.COORDINATES);
108 ejeY.setCoordinate(0,new Point3f(0.0f,-3.0f,-0.0f));
109 ejeY.setCoordinate(1,new Point3f(0.0f,3.0f,0.0f));
110
111 LineArray ejeY2 = new LineArray(2,LineArray.COORDINATES);
112 ejeY2.setCoordinate(0,new Point3f(0.0f,-3.0f,-0.0f));
113 ejeY2.setCoordinate(1,new Point3f(0.0f,3.0f,0.0f));
114
115 this.addChild(traslacion);
116 this.compile();
117 }
118
119 public void girarX(double alfa)
120 {
121 giroX = alfa-giroX;
122 //Transform3D girarEjeX = new Transform3D();
123 utility.rotX(giroX*Math.PI/180.0d);
124 rot.mul(utility);
125 rotacion.setTransform(rot);
126 giroX = alfa;
127 }
128
129 public void girarY(double alfa)
130 {
131 giroY = alfa-giroY;
132 //Transform3D girarEjeY = new Transform3D();
133 //girarEjeY.rotY(giroY*Math.PI/180.0d);
134 //rot.mul(girarEjeY);
135 utility.rotY(giroY*Math.PI/180.0d);
136 rot.mul(utility);
137 rotacion.setTransform(rot);
138 giroY = alfa;
139 }
140 public void girarZ(double alfa)
141 {
142 giroZ = alfa-giroZ;
143 //Transform3D girarEjeZ = new Transform3D();
144 //girarEjeZ.rotZ(giroZ*Math.PI/180.0d);
145 //rot.mul(girarEjeZ);
146 utility.rotZ(giroZ*Math.PI/180.0d);
147 rot.mul(utility);
148 rotacion.setTransform(rot);
149 giroZ = alfa;
150 }
151
152 public void girarParaboloide(double alfa)
153 {

Page 3 of 4
Paraboloide.java 31/01/2009 09:27 p.m.

154 giroPlato = alfa-giroPlato;


155 //Transform3D girarEjeZ = new Transform3D();
156 //girarEjeZ.rotZ(giroPlato*Math.PI/180.0d);
157 //rotarPlato.mul(girarEjeZ);
158 utility.rotZ(giroPlato*Math.PI/180.0d);
159 rotarPlato.mul(utility);
160 girarPlato.setTransform(rotarPlato);
161 giroPlato = alfa;
162 }
163
164 public void traslacion(double x, double y, double z)
165 {
166
167 }
168 public void escalar(double tamaño)
169 {
170 /*Transform3D cambioTamaño = new Transform3D();
171 cambioTamaño.setScale(tamaño);*/
172 utility.setScale(tamaño);
173 cambiarTamaño.setTransform(utility);
174 }
175 public void moverXYZ(float x, float y, float z)
176 {
177 this.x = x;
178 this.y = y;
179 this.z = z;
180 /*Transform3D trasladar = new Transform3D();
181 trasladar.setTranslation(new Vector3f(x,y,z));
182 traslacion.setTransform(trasladar);*/
183 utility.setTranslation(new Vector3f(x,y,z));
184 traslacion.setTransform(utility);
185 }
186 public void moverX( float x)
187 {
188 this.x = x;
189 moverXYZ((float)this.x,(float)this.y,(float)this.z);
190 }
191
192 public void moverY( float y)
193 {
194 this.y = y;
195 moverXYZ((float)this.x,(float)this.y,(float)this.z);
196 }
197 public void moverZ( float z)
198 {
199 this.z = z;
200 moverXYZ((float)this.x,(float)this.y,(float)this.z);
201 }
202 }
203

Page 4 of 4
Conoide
Conoide.java 31/01/2009 09:28 p.m.

1 //package patrones;
2
3 import javax.media.j3d.*;
4 import javax.vecmath.Color3f;
5 import javax.vecmath.Point3d;
6 import javax.vecmath.Vector3f;
7
8 public class Conoide extends BranchGroup
9 {
10 double alcance, anchoHaz,x,y,z;
11 int n,m;
12 TransformGroup rotacion,traslacion,cambiarTamaño;
13 double refZ,refX,refY;
14 Transform3D rot,
15 utility,utility2,utility3,utility4,utility5,utility6;
16 TransparencyAttributes ta;
17 Shape3D conoExterior;
18 Color3f amarillo;
19 float transparencia;
20 public Conoide(double altura, double anchoHaz, int m, int n, float
21 {
22 this.m = m;
23 this.n = n;
24 this.alcance = altura;
25 this.anchoHaz = anchoHaz;
26 this.transparencia = transparencia;
27 utility = new Transform3D();
28 utility2 = new Transform3D();
29 utility3 = new Transform3D();
30 utility4 = new Transform3D();
31 utility5 = new Transform3D();
32 utility6 = new Transform3D();
33
34 refX = 0.0;
35 refY = 0.0;
36 refZ = 0.0;
37 rot = new Transform3D();
38 this.x = 0.0;
39 this.y = 0.0;
40 this.z = 0.0;
41
42 ta = new TransparencyAttributes(TransparencyAttributes.SCREEN_D
43 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
44 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
45
46
47
48 amarillo = new Color3f(1.0f,1.0f,0.0f);
49 Color3f amarilloClaro = new Color3f(1.0f,1.0f,0.0f);
50
51 conoExterior = new Shape3D();

Page 1 of 5
Conoide.java 31/01/2009 09:28 p.m.

52 conoExterior.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
53 conoExterior.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
54 this.crearCono(this.alcance,this.anchoHaz,this.m,this.n,amarill
55
56
57 rotacion = new TransformGroup();
58 traslacion = new TransformGroup();
59 cambiarTamaño = new TransformGroup();
60 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
61 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
62 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
63 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
64 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_WRIT
65 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_READ
66 rotacion.addChild(conoExterior);
67 traslacion.addChild(rotacion);
68 this.addChild(traslacion);
69 this.compile();
70 }
71
72 public void girarX(double giroX)
73 {
74 /*Transform3D rotacionX = new Transform3D();
75 rotacionX.rotX((giroX-refX)*Math.PI/180.0d);
76 rot.mul(rotacionX);*/
77 utility.rotX((giroX-refX)*Math.PI/180.0d);
78 rot.mul(utility);
79 this.rotacion.setTransform(rot);
80 refX = giroX;
81 }
82
83 public void girarZ(double giroZ)
84 {
85
86 /*Transform3D rotacionZ = new Transform3D();
87 rotacionZ.rotZ((giroZ-refZ)*Math.PI/180.0d);
88 rot.mul(rotacionZ);*/
89 utility2.rotZ((giroZ-refZ)*Math.PI/180.0d);
90 rot.mul(utility2);
91 this.rotacion.setTransform(rot);
92 refZ = giroZ;
93 }
94
95 public void girarY(double giroY)
96 {
97 /*Transform3D rotacionY = new Transform3D();
98 rotacionY.rotY((giroY-refY)*Math.PI/180.0d);
99 rot.mul(rotacionY);*/
100 utility3.rotY((giroY-refY)*Math.PI/180.0d);
101 rot.mul(utility3);
102 this.rotacion.setTransform(rot);

Page 2 of 5
Conoide.java 31/01/2009 09:28 p.m.

103 refY = giroY;


104
105 }
106
107 public void traslacion(double x, double y, double z)
108 {
109
110 }
111 public void escalar(double tamaño)
112 {
113 /*Transform3D cambioTamaño = new Transform3D();
114 cambioTamaño.setScale(tamaño);*/
115 utility4.setScale(tamaño);
116 cambiarTamaño.setTransform(utility4);
117 }
118 public void moverXYZ(float x, float y, float z)
119 {
120 this.x = x;
121 this.y = y;
122 this.z = z;
123 /*Transform3D trasladar = new Transform3D();
124 trasladar.setTranslation(new Vector3f(x,y,z));*/
125 utility5.setTranslation(new Vector3f(x,y,z));
126 traslacion.setTransform(utility5);
127 }
128 public void moverX( float x)
129 {
130 this.x = x;
131 moverXYZ((float)this.x,(float)this.y,(float)this.z);
132 }
133
134 public void moverY( float y)
135 {
136 this.y = y;
137 moverXYZ((float)this.x,(float)this.y,(float)this.z);
138 }
139 public void moverZ( float z)
140 {
141 this.z = z;
142 moverXYZ((float)this.x,(float)this.y,(float)this.z);
143 }
144 public double getF1(int j, double deltaTetha)
145 {
146 if( j*deltaTetha <= 90)
147 {
148 double PI = Math.PI;
149 return Math.abs(Math.cos(j*deltaTetha*PI/180.0));
150 }
151 else
152 {
153 return 0.0;

Page 3 of 5
Conoide.java 31/01/2009 09:28 p.m.

154 }
155 }
156 public double getF2(int i, int k, double deltaPhi)
157 {
158 if (Math.abs((i+k)*deltaPhi) <= 360)
159 {
160 double PI = Math.PI;
161 return 1;
162 }
163 else
164 {
165 return 0.0;
166 }
167 }
168
169 public void ajustarTransparencia(float valorTransparencia)
170 {
171 ta.setTransparency(valorTransparencia);
172
173 }
174
175 private void crearCono(double altura,double anchoHaz, int m, int n,
176 Color3f color, float transparencia)
177 {
178 this.alcance = altura;
179 this.anchoHaz = anchoHaz;
180 this.m = m;
181 this.n = n;
182 double PI = Math.PI;
183 double deltaPhi = 360d/(this.n-1);
184 double tetha = this.anchoHaz/2.0;
185 double rmax = altura/Math.cos(tetha*PI/180.0);
186 double deltaRho = rmax/(this.m-1);
187 double posX,posY,posZ;
188 int formato = TriangleStripArray.COORDINATES | TriangleStripArr
189 Point3d punto = new Point3d();
190
191 int[] verticeporTiras = new int[this.n];
192 for (int s = 0;s < this.n ;s++ )
193 {
194 verticeporTiras[s] = 2*this.m;
195 }
196 TriangleStripArray geoPat1 =
197 new TriangleStripArray(2*this.m*this.n,formato,verticepo
198 for (int i = 0; i < n-1 ;i++ )
199 for (int j = 0; j< m-1;j++ )
200 for(int k = 0; k<2;k++)
201 {
202 posX = j*deltaRho*Math.sin(tetha*PI/180.0)*Math.cos((i+k)*d
203 posY = j*deltaRho*Math.sin(tetha*PI/180.0)*Math.sin((i+k)*d
204 posZ = j*deltaRho*Math.cos(tetha*PI/180.0);

Page 4 of 5
Conoide.java 31/01/2009 09:28 p.m.

205 punto = new Point3d(posX,posY,posZ);


206 geoPat1.setCoordinate(i*2*this.m+2*j+k,punto);
207 geoPat1.setColor(i*2*this.m+2*j+k,color);
208 }
209 PolygonAttributes apPoly = new PolygonAttributes();
210 apPoly.setCullFace(PolygonAttributes.CULL_NONE);
211 Appearance caraInterior = new Appearance();
212 caraInterior.setPolygonAttributes(apPoly);
213 caraInterior.setTransparencyAttributes(ta);
214 conoExterior.setGeometry(geoPat1);
215 conoExterior.setAppearance(caraInterior);
216
217 }
218 public void setAlcance(double alcance)
219 {
220 this.crearCono( alcance, this.anchoHaz, this.m, this.n,
221 amarillo, this.transparencia);
222 }
223 public void setAnchoHaz(double anchoHaz)
224 {
225 this.crearCono( this.alcance, anchoHaz, this.m, this.n,
226 amarillo, this.transparencia);
227
228 }
229
230 }
231

Page 5 of 5
Cono Luminoso
ConoLuminoso.java 31/01/2009 09:28 p.m.

1 import javax.media.j3d.*;
2 import javax.vecmath.*;
3
4 public class ConoLuminoso extends BranchGroup
5 {
6 TransformGroup rotacion,desplazarY;
7 Transform3D rot, utility,utility2,utility3,utility4,utility5,utilit
8 double giroX,giroY,giroZ;
9 TransparencyAttributes transparencia;
10
11 public ConoLuminoso(float angulo,float altura, float valorTranspare
12 {
13 utility = new Transform3D();
14 utility2 = new Transform3D();
15 utility3 = new Transform3D();
16 utility4 = new Transform3D();
17 utility5 = new Transform3D();
18 utility6 = new Transform3D();
19 giroX = 0.0;
20 giroY = 0.0;
21 giroZ = 0.0;
22 rotacion = new TransformGroup();
23 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
24 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
25 Transform3D rotar90 = new Transform3D();
26 rotar90.rotX(270.0*Math.PI/180.0d);
27 rot = new Transform3D();
28
29 TransformGroup rotX = new TransformGroup();
30 rotX.setTransform(rotar90);
31 Transform3D desplazamientoY = new Transform3D();
32 desplazamientoY.setTranslation(new Vector3f(0.0f,-altura/2.0f,0
33 desplazarY = new TransformGroup();
34 desplazarY.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
35 desplazarY.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
36 desplazarY.setTransform(desplazamientoY);
37
38
39 Appearance apariencia = new Appearance();
40 ColoringAttributes amarillo = new ColoringAttributes
41 (new Color3f(1.0f,1.0f,0.0f),
42 ColoringAttributes.SHADE_GOURAUD)
43
44 transparencia =
45 new TransparencyAttributes(TransparencyAttributes.BLENDED,
46 valorTransparencia);
47 transparencia.setCapability(TransparencyAttributes.ALLOW_VA
48 transparencia.setCapability(TransparencyAttributes.ALLOW_VA
49 apariencia.setColoringAttributes(amarillo);
50 apariencia.setTransparencyAttributes(transparencia);
51 com.sun.j3d.utils.geometry.Cone cono =

Page 1 of 3
ConoLuminoso.java 31/01/2009 09:28 p.m.

52 new com.sun.j3d.utils.geometry.Cone((float) (al


53 altura,com.sun.j3d.utils.geome
54 desplazarY.addChild(cono);
55 rotX.addChild(desplazarY);
56 rotacion.addChild(rotX);
57 this.addChild(rotacion);
58
59 this.compile();
60
61 }
62
63
64 public void girarX(double alfa)
65 {
66 System.out.println("CONOLUMINOSO EJE X");
67 giroX = alfa-giroX;
68 /*Transform3D girarEjeX = new Transform3D();
69 girarEjeX.rotX(giroX*Math.PI/180.0d);
70 rot.mul(girarEjeX);*/
71 utility.rotX(giroX*Math.PI/180.0d);
72 rot.mul(utility);
73 rotacion.setTransform(rot);
74 giroX = alfa;
75 }
76
77 public void girarY(double alfa)
78 {
79 System.out.println("CONOLUMINOSO EJE Y");
80 giroY = alfa-giroY;
81 /*Transform3D girarEjeY = new Transform3D();
82 girarEjeY.rotY(giroY*Math.PI/180.0d);
83 rot.mul(girarEjeY);*/
84 utility2.rotY(giroY*Math.PI/180.0d);
85 rot.mul(utility2);
86 rotacion.setTransform(rot);
87 giroY = alfa;
88 System.out.println("?????????");
89 }
90 public void girarZ(double alfa)
91 {
92 System.out.println("CONOLUMINOSO EJE Z");
93 giroZ = alfa-giroZ;
94 /*Transform3D girarEjeZ = new Transform3D();
95 girarEjeZ.rotZ(giroZ*Math.PI/180.0d);
96 rot.mul(girarEjeZ);*/
97 utility3.rotZ(giroZ*Math.PI/180.0d);
98 rot.mul(utility3);
99 rotacion.setTransform(rot);
100 giroZ = alfa;
101 System.out.println("?????????");
102 }

Page 2 of 3
ConoLuminoso.java 31/01/2009 09:28 p.m.

103 public void ajustarTransparencia(float valorTransparencia)


104 {
105 transparencia.setTransparency(valorTransparencia);
106 }
107
108 }
109

Page 3 of 3
Patron1
Patron1.java 31/01/2009 10:07 p.m.

1 //package patrones;
2
3 import javax.media.j3d.*;
4 import javax.vecmath.Color3f;
5 import javax.vecmath.Point3d;
6 import javax.vecmath.Vector3f;
7
8 public class Patron1 extends BranchGroup
9 {
10 double diametro, rfd,x,y,z;
11 int n,m;
12 TransformGroup rotacion,traslacion,cambiarTamaño;
13 double refZ,refX,refY;
14 Transform3D rot, utility,utility2,utility3,utility4,utility5,utilit
15 TransparencyAttributes ta;
16
17 public Patron1(double A, double potPhi,double potTetha, int n , int
18 {
19 utility = new Transform3D();
20 utility2 = new Transform3D();
21 utility3 = new Transform3D();
22 utility4 = new Transform3D();
23 utility5 = new Transform3D();
24 utility6 = new Transform3D();
25 refX = 0.0;
26 refY = 0.0;
27 refZ = 0.0;
28 rot = new Transform3D();
29 this.x = 0.0;
30 this.y = 0.0;
31 this.z = 0.0;
32 this.diametro = diametro;
33 this.rfd = rfd;
34 this.m = m;
35 this.n = n;
36 int[] verticeporTiras = new int[n];
37 int formato = TriangleStripArray.COORDINATES | TriangleStripArr
38 Point3d punto = new Point3d();
39 double posX,posY,posZ;
40 double deltaPhi = 360/(this.n-1);
41 double deltaTetha = 180/(this.m-1);
42 Color3f azul = new Color3f(0.0f,0.0f,1.0f);
43 for (int s = 0;s < n ;s++ )
44 {
45 verticeporTiras[s] = 2*m;
46 }
47 TriangleStripArray geoPat = new TriangleStripArray(2*m*n,format
48
49 double PI = Math.PI;
50 double r,f1,f2;
51

Page 1 of 4
Patron1.java 31/01/2009 10:07 p.m.

52 for (int i = 0; i < n ;i++ )


53 for (int j = 0; j<m ;j++ )
54 for(int k = 0; k<2;k++)
55
56 {
57 f1 = getF1(j,deltaTetha);
58 f2 =getF2(i,k,deltaPhi);
59 r = A*Math.pow(f1,potTetha)*Math.pow(f2,potPhi);
60 posX = r*Math.sin(j*deltaTetha*PI/180.0)*Math.cos((i+k)*del
61 posY = r*Math.sin(j*deltaTetha*PI/180.0)*Math.sin((i+k)*del
62 posZ = r*Math.cos(j*deltaTetha*PI/180.0);
63 punto = new Point3d(posX,posY,posZ);
64 geoPat.setCoordinate(i*2*m+2*j+k,punto);
65 geoPat.setColor(i*2*m+2*j+k,azul);
66 }
67
68 PolygonAttributes apPoly = new PolygonAttributes();
69 apPoly.setCullFace(PolygonAttributes.CULL_NONE);
70 Appearance caraAnterior = new Appearance();
71 caraAnterior.setPolygonAttributes(apPoly);
72 ta = new TransparencyAttributes(TransparencyAttributes.BLENDED,
73 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
74 ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
75 caraAnterior.setTransparencyAttributes(ta);
76 Shape3D patron = new Shape3D(geoPat,caraAnterior);
77
78 rotacion = new TransformGroup();
79 traslacion = new TransformGroup();
80 cambiarTamaño = new TransformGroup();
81 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
82 rotacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
83 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
84 traslacion.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
85 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_WRIT
86 cambiarTamaño.setCapability(TransformGroup.ALLOW_TRANSFORM_READ
87 rotacion.addChild(patron);
88 traslacion.addChild(rotacion);
89 this.addChild(traslacion);
90 this.compile();
91 }
92
93 public void girarX(double giroX)
94 {
95 /*Transform3D rotacionX = new Transform3D();
96 rotacionX.rotX((giroX-refX)*Math.PI/180.0d);
97 rot.mul(rotacionX);*/
98 utility.rotX((giroX-refX)*Math.PI/180.0d);
99 rot.mul(utility);
100 this.rotacion.setTransform(rot);
101 refX = giroX;
102 }

Page 2 of 4
Patron1.java 31/01/2009 10:07 p.m.

103
104 public void girarZ(double giroZ)
105 {
106
107 /*Transform3D rotacionZ = new Transform3D();
108 rotacionZ.rotZ((giroZ-refZ)*Math.PI/180.0d);
109 rot.mul(rotacionZ);*/
110 utility2.rotZ((giroZ-refZ)*Math.PI/180.0d);
111 rot.mul(utility2);
112 this.rotacion.setTransform(rot);
113 refZ = giroZ;
114 }
115
116 public void girarY(double giroY)
117 {
118 /*Transform3D rotacionY = new Transform3D();
119 rotacionY.rotY((giroY-refY)*Math.PI/180.0d);*/
120 utility3.rotY((giroY-refY)*Math.PI/180.0d);
121 rot.mul(utility3);
122 this.rotacion.setTransform(rot);
123 refY = giroY;
124
125 }
126
127 public void traslacion(double x, double y, double z)
128 {
129
130 }
131 public void escalar(double tamaño)
132 {
133 /*Transform3D cambioTamaño = new Transform3D();
134 cambioTamaño.setScale(tamaño);*/
135 utility4.setScale(tamaño);
136 cambiarTamaño.setTransform(utility4);
137 }
138 public void moverXYZ(float x, float y, float z)
139 {
140 this.x = x;
141 this.y = y;
142 this.z = z;
143 /*Transform3D trasladar = new Transform3D();
144 trasladar.setTranslation(new Vector3f(x,y,z));*/
145 utility6.setTranslation(new Vector3f(x,y,z));
146 traslacion.setTransform(utility6);
147 }
148 public void moverX( float x)
149 {
150 this.x = x;
151 moverXYZ((float)this.x,(float)this.y,(float)this.z);
152 }
153

Page 3 of 4
Patron1.java 31/01/2009 10:07 p.m.

154 public void moverY( float y)


155 {
156 this.y = y;
157 moverXYZ((float)this.x,(float)this.y,(float)this.z);
158 }
159 public void moverZ( float z)
160 {
161 this.z = z;
162 moverXYZ((float)this.x,(float)this.y,(float)this.z);
163 }
164 public double getF1(int j, double deltaTetha)
165 {
166 if( j*deltaTetha <= 90)
167 {
168 double PI = Math.PI;
169 return Math.abs(Math.cos(j*deltaTetha*PI/180.0));
170 }
171 else
172 {
173 return 0.0;
174 }
175 }
176 public double getF2(int i, int k, double deltaPhi)
177 {
178 if (Math.abs((i+k)*deltaPhi) <= 360)
179 {
180 double PI = Math.PI;
181 return 1;
182 }
183 else
184 {
185 return 0.0;
186 }
187 }
188
189 public void ajustarTransparencia(float valorTransparencia)
190 {
191 ta.setTransparency(valorTransparencia);
192 }
193
194 }
195

Page 4 of 4

Potrebbero piacerti anche