Printing edge/corner coordinates of triangulated convex/concave polygon in the right order

It's about convex and concave polygons, triangulation is already done: every coordinate pair of x,y lies at an edge/corner.

Polygon array consists of n triangles à 3 x,y coordinate pairs:
triangle1: x0,y0,x1,y1,x2,y2
triangle2: x0,y0,x1,y1,x2,y2 etc.
This is the only information we have.

I need an algorithm/example code, which prints all relevant coordinate pairs in the right order so a border line can be drawn later on with help of that information.

It should work with triangulated convex and concave polygons equally which are stored in a way like with PolygonArray.

Is it possible with the information given? Can't even imagine what numbers I would need to check in order to get the relevant coordinate info.
Many thanks in advance.

If you copy this code into cpp (you need sfml for this as well), then you will see the polygon on the screen as it's not possible to upload images here.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <SFML/Graphics.hpp>
#include <iostream>
#include <array>

std::array<float, 48> PolygonArray = { 337.8, 657.25, 247.5, 654.25, 260, 366.5, 260, 366.5, 347.8, 257, 474.5, 235,
474.5, 235, 816.3, 211, 859.8, 372, 859.8, 372, 838.3, 432, 709, 566, 538, 562, 337.8, 657.25, 260, 366.5, 260, 366.5,
474.5, 235, 859.8, 372, 859.8, 372, 709, 566, 538, 562, 538, 562, 260, 366.5, 859.8, 372};

std::vector<sf::VertexArray> PolygonVector;
sf::VertexArray triangle(sf::Triangles, 3);

int main()
{
	sf::RenderWindow window(sf::VideoMode(1200, 900), "Test");

	for (int i = 0; i < PolygonArray.size()/6; i++) // / 6 = 3 * x,y = triangle
	{
		triangle[0].position = sf::Vector2f(PolygonArray[i * 6 + 0], PolygonArray[i * 6 + 1]);
		triangle[1].position = sf::Vector2f(PolygonArray[i * 6 + 2], PolygonArray[i * 6 + 3]);
		triangle[2].position = sf::Vector2f(PolygonArray[i * 6 + 4], PolygonArray[i * 6 + 5]);
		triangle[0].color = triangle[1].color = triangle[2].color = sf::Color(255, i * 30, i * 30);
		PolygonVector.push_back(triangle);
	}

	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
		}
		window.clear();
		window.setFramerateLimit(30);
		for (auto& it = PolygonVector.begin(); it != PolygonVector.end(); ++it)
		{
			window.draw(*it);
		}
		window.display();
	}
}
Last edited on
Topic archived. No new replies allowed.