2

I am trying to draw an interactive planar straight line graph (PSLG) on a JApplet. I am using mouse-clicks to determine the vertices of the PSLG.

Here is the algorithm which I am following for drawing edges of the PSLG 1. The point where user performs a mouse-click is added as a vertex of the PSLG. 2. If he clicks a second point,an edge is directly created among the point and the previously clicked-point

Here are certain flaws which I observed due to the use of this algorithm:

  1. Inability to create disjoint-planar sets like say just a line segment
  2. A closed polygon is only created if the user clicks at the exact location where the start point was [Essentially, if the user clicks very close to the start point, there is no way to tell that this point is actually the start point since it appears within a certain tolerance range from the point].

I've checked out some similar questions over here and people suggest to use the JFreeChart library. But as far as I get, the scenario in those questions was that the points of the PSLG were already known. I do not know whether JFreeChart can be used for creating interactive PSLG's

I thought about adding points and having a button which would say add edges among points,but if that's the case selecting the 2 points will still involve the proximity problem encountered in 2.

I was wondering if anybody could suggest me a better approach on how to handle this situation.

Thanks in advance

chaitanya
  • 1,591
  • 2
  • 24
  • 39

1 Answers1

4

GraphPanel could be adapted to this task, although it might benefit from a more advanced edge model for faster searching. Also consider JGraph.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045