0

So I created two Objects in my Java program, a Point object (in 2d space, containing two double class variables, one for x and one for y), as well as a LineSegment class, with the two endpoints as its class variables.

I also created a Path class later on, with an array of points as its class variable, the order of the points determining the path and assuming the first point is the starting point and each subsequent point is visited in order, traversing between points in a straight direction.

How can I determine, given a set of points, all of the possible paths, with a specified starting and ending point, and a rule that none of these paths can revisit any points for any reason?

Thanks!

CCovey
  • 799
  • 1
  • 10
  • 17
  • You seem to be over-engineering your graph data-structure. You can use a adjacency matrix or an adjacency list to represent points(nodes) and lines(edges) instead and then use something like the Floyd Warshall Algorithm to find paths between nodes – Pramod Apr 17 '15 at 16:23

1 Answers1

1

I see a possible problem with your model. How do you go from LineSegment to LineSegment? Doubles suck when it comes to comparing for equality making finding all LineSegments at a point difficult. Maybe a Node class to represent a vertex. It would hold a Point and a collection of other connected Node objects.

Also, take a look at Find all paths between two graph nodes

Community
  • 1
  • 1
candied_orange
  • 7,036
  • 2
  • 28
  • 62