1

I'm trying to implement Lee's visibility graph.

There might be n number of polygons, where each side of the polygon is an edge. Let's say there is a point p1, and a half-liner parallel to the positive x-axis start at p1. I need to find edges that are intersected by r, and store them in sorted order.

An edge that is intersected first by line r has higher priority, also an edge that's closer has a higher priority, but when seen > distance.

E.g p1 = (0, 1), and a polygon with the following vertices {(2, 4),(3,6),(5, 20)}. The edges for this polygon should be sorted as [((2, 4),(5, 20)), ((2,4),(3, 6)), ((3, 6),(5, 20))].

Hence, how can I sort these edges?

(if you go to the link and read that, I think you will have a better idea, sorry for my explanation).

My prime idea: sort them by distance and angel from p1 to the first Vertex of the edge encountered by r. Though, all vertices have more than one edge (since each vertex/edge is part of a polygon), and I don't know how to sort these two.

Any ideas or hints would be much appreciated.

Just some references: https://taipanrex.github.io/2016/10/19/Distance-Tables-Part-2-Lees-Visibility-Graph-Algorithm.html And a book: Computational Geometry ALgorithms and Application.

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80

1 Answers1

0

I found a way for those who are interested:

The sweep line is rotating anti-clockwise and its ordering edges based on taking measurements when it encounters the first vertice of that edge, which are: angle between the initial position of the half line (when it's parallel to positive x-axis) and the vertice encountered, the distance between p1 and the encountered vertice. The smaller the angle and distance the better, also angle has higher priority than distance.

I also take a 3rd measurement, since the half line rotates, when it reaches a vertice it should intersect it, hence I take the angle between the half line and the edge of the vertice. The large the angle the higher priority for this one, since it means the edge is closer. This angle is to differentiate between edges that have the same first encountered vertice by the half line. Therefore, the priority for this measurement is the lowest.

Hopefully, this will help someone.