0

I am currently learning libGDX, and doing stuff with meshes. I need to give the video card some triangles, to render.

My current task is so. Having several rectangles at some points on some "box" (each rectangle having origin point, width and height), separate the outer part of the rectangles into rectangles itself. after having those small rectangles I can can divide them into triangles and easily render. Like this. enter image description here

Having blue rectangle info. I need to have something like this. after having those rectangles outlined in orange, I can can divide them into triangles and easily render. enter image description here

My approach is this. "drawing" horizontal lines from top and bottom of each rectangle until reaches the wall of the box or wall of other rectangle. Doing this, the field will be separated in rectangles like this enter image description here Which is basically what I need. Currently can't imagine the programmatic approach. Any help will be appreciated. Thanks. I will implement it in Java.

1
  • 1
    I recommend asking this question on the LibGDX forum. StackOverflow is not really orfanized toward open-ended questions like this that require discussion.
    – Tenfour04
    Jul 28, 2018 at 2:10

1 Answer 1

1

What you've drawn breaks down into two steps.

Step 1 is commonly known as "trapezoidal decomposition", which you can google for a lot of in depth information. To make a trapezoidal decomposition:

  • Find all the y coordinates at which there is a vertex or intersection and sort them.
  • Then, each horizontal strip between each pair of adjacent y coordinates must consist of trapezoids with tops and bottoms on the strip edges, because there can be no corners or intersections within the strip. Find the parts of each polygon or edge that spans the strip to create the trapezoidal decomposition.

Horizontal strips of trapezoids are easy to convert into triangle strips just by adding a cutting edge across opposite corners of each trapezoid, but to get what you drew you need a second step.

In Step 2 you go through the pairs of adjacent strips and combine their trapezoids where possible. This will coalesce all the parts of each rectangle back together, and get rid of thin strips on either side of the big one, leaving exactly the strip decomposition you drew.

1
  • Thanks for the answer. I didn't understand second point of step 1, could you please explain it in more simple terms please? Thanks. Jul 28, 2018 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.