0

I have a convex polygon and some points. I have to form a line between 2 points and then form a triangle with another point. The point from inside the triangle are inside the polygon too. The algorithm continues by forming triangles until finding all the points belonging to the polygon. I need some help, 'cause I'm new to java and don't know how to solve this problem. I managed to write the function to check if a point belongs to the line created.

   public static void calculateLine(Point Q, Point P, Point x) {
        double a, b;
        a = Q.y - P.y;
        b = P.x - Q.x;
        double c = a * (P.x) + b * (P.y);
        if (a * x.x + b * x.y == c)
            System.out.println("point belongs to line");
        else {
            System.out.println("point doesn't belong to line");
        }
    }
}
  • "I'm new to java" - that's not a problem related specifically to Java but rather an algorithmic problem. Have a look here for some info: https://stackoverflow.com/questions/217578/how-can-i-determine-whether-a-2d-point-is-within-a-polygon – Thomas Apr 18 '19 at 14:19
  • @Thomas i read the article, but it doesn't treat the case with creating triangles and testing by this method. – Library System Apr 18 '19 at 14:24
  • What's the problem then? Is it how to form the triangles and test the points? That's what the link should describe. Or is it how to determine the points that should form a triangle? – Thomas Apr 18 '19 at 14:44
  • @Thomas, how to determine the points that should form a triangle ... – Library System Apr 18 '19 at 16:50
  • Hmm, you're already describing the algorithm you need to implement, don't you? So don't you have a description of what to do already? If not then a simplistic approach could be to randomly pick a random point that's not yet inside the current polygon and find the nearest edge of the polygon (i.e. pick the line with the smallest distance to that point) and form a triangle of those. If the algorithm is not set then I'd suggest looking at one of the many to be found on the net, e.g. [Delaunay triangulation](https://en.wikipedia.org/wiki/Delaunay_triangulation) – Thomas Apr 23 '19 at 08:16

0 Answers0