Created
February 26, 2010 11:42
-
-
Save Cerr0s/315657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.Graphics2D; | |
import java.awt.geom.*; | |
import java.util.ArrayList; | |
public class Nodo { | |
double x, y; | |
private Point2D Origen; | |
Rectangle2D Cuadro; | |
ArrayList<Arista> Aristas; | |
ArrayList<Nodo> Adyacentes; | |
double Distancia; | |
private boolean Visitado; | |
/* Constructor de la Clase Nodo */ | |
public Nodo () { | |
this.setVisitado(false); | |
} | |
/* Constructor de la Clase Nodo */ | |
public Nodo (Point2D Punto, double Distancia) { | |
this.Distancia = Distancia; | |
this.x = Punto.getX(); | |
this.y = Punto.getY(); | |
Adyacentes = new ArrayList<Nodo>(); | |
Cuadro = new Rectangle2D.Double(x - 3, y - 3, 6, 6); | |
Origen = Punto; | |
Aristas = new ArrayList<Arista>(); | |
} | |
/* Metodo que Dibuja un Nodo */ | |
public void pintaNodo (Graphics2D g2) { | |
g2.setColor(Color.blue); | |
g2.fill(Cuadro); | |
} | |
/* Metodo que Genera las Aristas del Arbol que se van a Pintar */ | |
public void generaAristas (Lienzo L) { | |
double x2, y2; | |
Point2D PuntoNuevo; | |
Arista AristaNueva; | |
Nodo NodoNuevo; | |
Boolean Pintable = true; | |
int Grados = 0; | |
/* Se Crean las 12 Aristas de Cada Nodo | |
* El Angulo Para Cada Arista de los Nodos, | |
* debe ser de 30 Grados. | |
*/ | |
for (int i = 0; i < 12; i++) { | |
x2 = x + Distancia * Math.sin (Grados * (Math.PI/180)); | |
y2 = y - Distancia * Math.cos (Grados * (Math.PI/180)); | |
if (x2 > 0 && y2 > 0) { | |
PuntoNuevo = new Point2D.Double(x2, y2); | |
NodoNuevo = new Nodo(PuntoNuevo, Distancia); | |
AristaNueva = new Arista(this, NodoNuevo); | |
Adyacentes.add(NodoNuevo); | |
Aristas.add(AristaNueva); | |
Grados += 30; | |
} | |
} | |
} | |
/* Metodo get para obtener el Punto del Nodo */ | |
public Point2D getOrigen () { | |
return Origen; | |
} | |
/* Metodo is para saber si el Nodo fue Visitado o No */ | |
public boolean isVistitado () { | |
return Visitado; | |
} | |
/* Metodo set para indicr si el Nodo es Visitado */ | |
public void setVisitado (boolean Visitado) { | |
this.Visitado = Visitado; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment