Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to use org.eclipse.draw2d.graph.ShortestPathRouter?
How to use org.eclipse.draw2d.graph.ShortestPathRouter? [message #1065838] Thu, 27 June 2013 17:27 Go to next message
Inshua Shimin is currently offline Inshua Shimin
Messages: 2
Registered: June 2013
Junior Member
Dear All,

i am searching some algorithm code to find shortest path avoiding square obstacles, so i found org.eclipse.draw2d.graph.ShortestPathRouter by google.

i've study RouteEdges for its usage, and got a peice of code as below

public static void main(String[] args) {
		Point start = new  Point(1,2);
		Point end = new Point(5,2);
		Rectangle rect = new Rectangle(2, 1, 2, 2);
		
		ShortestPathRouter router = new ShortestPathRouter();
		Path path = new Path(start, end);
		router.addPath(path);
		
		router.addObstacle(rect);
		
		router.setSpacing(0);
		router.solve();
		
		System.out.println("solved");
		PointList ls = path.getPoints();
		for(int i=0; i<ls.size(); i++){
			System.out.print(ls.getPoint(i).toString() + "\t");  
		}
		System.out.println();
	}


here i just put a rectangle(2,1 -- 4,3) between two point (1,2) and (5,2). at last i got a strange result as :

Point(1, 2) Point(2, 2) Point(3, 2) Point(5, 2)

did i misunderstood ShortestPathRouter?

and do you know any other effective find-path-avoiding-square-obstacles algorithm? not grid + A-star


Thanks

[Updated on: Fri, 28 June 2013 10:50]

Report message to a moderator

Re: How to use org.eclipse.draw2d.graph.ShortestPathRouter? [message #1067012 is a reply to message #1065838] Fri, 05 July 2013 12:42 Go to previous message
Inshua Shimin is currently offline Inshua Shimin
Messages: 2
Registered: June 2013
Junior Member
it's all right, i'd gave too little scale rectangles, when i scale everything 10 times, everything changed!
new code:

public static void main(String[] args) {
			Point start = new  Point(10,20);
			Point end = new Point(50,20);
			Rectangle rect = new Rectangle(20, 10, 20, 20);
			
			ShortestPathRouter router = new ShortestPathRouter();
			Path path = new Path(start, end);
			router.addPath(path);
			
			router.addObstacle(rect);
			
			//router.setSpacing(5);
			router.solve();
			
			System.out.println("solved");
			PointList ls = path.getPoints();
			for(int i=0; i<ls.size(); i++){
				System.out.print(ls.getPoint(i).toString() + "\t");  
			}
			System.out.println();
		}


got result :

Point(10, 20) Point(16, 33) Point(43, 33) Point(50, 20)

AH
Previous Topic:[ZEST] GraphNode self-loop display
Next Topic:Display issues with Zest GraphConainers
Goto Forum:
  


Current Time: Tue Sep 30 19:57:19 GMT 2014

Powered by FUDForum. Page generated in 0.02004 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software