Im trying to implement voronoi diagram generation.
Currently its working like this: When site event happens we find a intersection point between x = const and some parabol. From this point we will draw through a bisecting line between parabols focus and current site. The line consists of 2 rays initally. Both start at the intersection point, one goes to left and other to right. Additionally for bisecting lien i have the i know the f and g from y = f*x +g.
During a circle event(getting a vertex that joins 2 edges) i need to find the intersection point of 2 edges. The following code works fine if the midpoint(start of 2 rays) lies between the 2 edge intersections. But it seems to me that quite often it happens that the mid point is beyond one of the intersection points, and then the intersection does not happen.
Can someone find the issue with the code? I followed an instruction(read the C++ code in: http://blog.ivank.net/fortunes-algorithm-and-implementation.html) where sweepline moved from top to bottom and (0,0) is top left. My sweepline moves from top to bottom and (0,0) is bottom left. So some math somewhere is off.
Full code: https://codeshare.io/GLWRQb
public Vector3 RayIntersection(VoronoiEdge a, VoronoiEdge b)
{
float x = (b.g - a.g) / (a.f - b.f);
float y = a.f * x + a.g;
if ((x - a.start.x) * a.dx < 0) return Vector3.zero;
if ((y - a.start.y) * a.dy < 0) return Vector3.zero;
if ((x - b.start.x) * b.dx < 0) return Vector3.zero;
if ((y - b.start.y) * b.dy < 0) return Vector3.zero;
return new Vector3(x,y);
}
Edit:
After some trial and error i have found that the problem is not the intersection check. But in some cases it happens that wrong edges are compared.