i have a problem. first sorry for my english. down are my declarations and definitions for a graph that can be directed and not. The definition for the edges are now that you can create only an edge that can go directly from one vertex to the other. I don't know how to change the definition that i can make also an edge that
is not a streight line but it can have 90 degree corners(like a polyline - exsactly like in the picture under the Thank You)
If no one knows how to do this, pleas give me the edge definition that do what i need and i will change my program
i have forgotten to tel that the edge must be declared as it is one line with corners not made of two or three lines.
class Vertex //vertex definition { public int x; public int y; public Color color; public int dist; public int pred; public boolean S; public boolean show; } ////////////////////////////////////////////////////// class Edge //edge definition { public int v1; public int v2; public int midX; public int midY; public int left; public Color color; } //////////////////////////////////////////////////////////////////
public void update(Graphics g) //draw graph { paint(g); }
public void paint(Graphics g) { Dimension size = size(); Image bufferedImage=createImage(size.width, size.height); Graphics bg = bufferedImage.getGraphics(); bg.setColor(Color.black); Font f = new Font("SanSerif", Font.PLAIN, 12); bg.setFont(f);
public void drawEdge(Graphics g, int i) //draw edge { int x1=vertices[edges.v1].x+DIA/2; int y1=vertices[edges.v1].y+DIA/2; int x2=vertices[edges.v2].x+DIA/2; int y2=vertices[edges.v2].y+DIA/2;
} /*g.setColor(Color.white); g.drawString(""+Adj[edges.v1][edges.v2], edges.midX, edges.midY); g.drawString(""+edges.left, edges.midX, edges.midY);*/ } //////////////////////////////////////////////////////////////////////// public void addVertex(int x, int y) //add vertex in graph { if (nvertices<MAXVERTICES) { Vertex v = new Vertex(); v.x = x-DIA/2; v.y = y-DIA/2; v.color = new Color(250, 200, 100); v.dist = 0; v.pred = -1; v.S=false; v.show=true; vertices[nvertices++] = v; } repaint(); } /////////////////////////////////////////////////////////////////////////// public void moveVertex(int i, int x, int y) //move vertex in graph { vertices.x=x-DIA/2; vertices.y=y-DIA/2; repaint(); } ////////////////////////////////////////////////////////////////////////// public void selectVertex(int i) //select vertex in graph { if(startVertex==i) { reset(); startVertex=-1; } else if(targetVertex==i) { reset(); targetVertex=-1; } else if(startVertex<0) startVertex=i; else if (targetVertex<0) targetVertex=i; else { reset(); startVertex=i; targetVertex=-1; }
repaint(); }
public int findVertex(int x, int y) { for(int i=0;i<nvertices;i++) { if((x>vertices.x-DIA/2)&&(x<vertices.x+DIA) && (y>vertices.y-DIA/2)&&(y<vertices.y+DIA)) return i; } return -1; } ///////////////////////////////////////////////////////////////////////////// // public void deleteVertex(int breakPoint) //delete vertex from graph { vertices[breakPoint].show=false; for(int i=0;i<nvertices;i++) { for(int j=0;j<nedges;j++) if((edges[j].v1==breakPoint&&edges[j].v2==i)|| (edges[j].v1==i&&edges[j].v2==breakPoint)) deleteEdge(j);
if(digraph&&Adj[breakPoint]>0) { for(int j=0;j<nedges;j++) if(edges[j].v1==i&&edges[j].v2==breakPoint) deleteEdge(j); } } repaint(); } ///////////////////////////////////////////////////////////////////////////// /// //add edge in graph public void addEdge(int V1, int V2, int weightIn, int levin) { if(digraph) // if the edge is in both ways with the same waight { Adj[V1][V2]=weightIn; lev[V1][V2]=levin; } else // if it is a directed edge { Adj[V1][V2]=weightIn; Adj[V2][V1]=weightIn; lev[V1][V2]=levin; lev[V2][V1]=levin; }
if(!digraph) //the edge is not directed but is in both // ways, from and to the vertex { Edge e2 = new Edge(); e2.v1=V2; e2.v2=V1; e2.color = Color.black; e1.midX=0; e1.midY=0; edges[nedges++]=e2; } repaint(); } ///////////////////////////////////////////////////////////////////////////// ////// public void deleteEdge(int breakPoint) { if(!digraph) { Adj[edges[breakPoint].v1][edges[breakPoint].v2]=-1; Adj[edges[breakPoint].v2][edges[breakPoint].v1]=-1; lev[edges[breakPoint].v1][edges[breakPoint].v2]=-1; lev[edges[breakPoint].v2][edges[breakPoint].v1]=-1; } else Adj[edges[breakPoint].v1][edges[breakPoint].v2]=-1; lev[edges[breakPoint].v1][edges[breakPoint].v2]=-1;
public void changeWeight(int i, int newWeight) { Adj[edges.v1][edges.v2]=newWeight; repaint(); }
public void changeLeft(int i, int newLeft) { lev[edges.v1][edges.v2]=newLeft; repaint(); }
public int findEdge(int x, int y) { for(int i=0;i<nedges;i++) { if((x>edges.midX-8)&&(x<edges.midX+8) &&(y>edges.midY-8)&&(y<edges.midY+8)) return i; }
return -1; }
public int getMin() { int minV; int min; int breakPoint;