views:

535

answers:

1

Given a path expressed as an array of 2d points:

Point[] path = new Point[4]
{
    new Point(0,0),
    new Point(10,0),
    new Point(10,10),
    new Point(0,10),
};

... Here, a box.

What is the best way to convert this to a list of triangles (which fill the path) to be used in a 3D application? Given that this is only a simple example and the path may be fairly complex in reality. Is there anything already in the framework, maybe System.Drawing or in WPF which would help with this?

Edit: (After the comment by Samuel) Ideally, I'l like to be able to deal with both convex and concave polygons, else the graphic will have to be up of many convex polygons manually..

+4  A: 

It depends on what the path consists of, and how it's created.

If it's always a convex polygon, you can create a triangle fan very easily that will fill in the region.

If it's not a convex polygon, you will most likely need to use some form of triangulation to fill in the path. There are quite a few options out there. Most of the sample code is in C or C++, not in C#, but this might help:

http://local.wasp.uwa.edu.au/~pbourke/papers/triangulate/morten.html

The basic idea is to fill in the outer boundaries, and the triangulation routine will pass back the correct triangle indices required for your 3D app.

There isn't anything in the framework that will do this for you.

Reed Copsey