I'm having trouble trying to find all vertices on polygons that are visible from a given vertex on a polygon. So far I've had limited success with what I've written.
I can generate the rays to visible vertices, but only if my origin point is not on a vertex using the following:
private ArrayList<Polyline> getGloballyVisible(Point2D origin, ArrayList<Polygon> polys) {
ArrayList<Polyline> visible = new ArrayList<>();
for (Polygon target : polys) {
ArrayList<Polyline> targetVisibleLines = getVisiblePointsOnPolygon(origin, target);
ArrayList<Polygon> subTargetPolygons = new ArrayList<>(polys);
subTargetPolygons.remove(target);
ArrayList<Polyline> subTargetEdges = getEdges(subTargetPolygons);
lineCheck: for (Polyline line : targetVisibleLines) {
for (Polyline enemyLine : subTargetEdges) {
ArrayList<Point2D> linePoints = toPoints(line.getPoints());
ArrayList<Point2D> enemyLinePoints = toPoints(enemyLine.getPoints());
if (linesIntersect(linePoints.get(0), linePoints.get(1), enemyLinePoints.get(0), enemyLinePoints.get(1))) {
continue lineCheck;
}
}
visible.add(line);
}
}
return visible;
}
Full code here, please don't laugh.
This is the last approach I've tried. I'm sure this way is horrible, if someone could point me in the right direction so can make it less horrible I'd appreciate it.