# Calculate number of sides

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i want to calculate the number of sides in the meshes I load, is there any way i could do it, i know the number of verts in a mesh but i can't figure out how to get the sides. And I want to do it manually, meaning without using one of D3D functions. Thnx

##### Share on other sites
Quote:
 I want to do it manually, meaning without using one of D3D functions.
Well if you don't want to use the D3D API I'll push this over to the GP&T forum - the 'DirectX' forum is more for specifics of the API and technology than, as you request, general graphics algorithms [wink]

I'd personally step through each face and do a dot-product between neighbours using a threshold function to determine which were different "sides". You need to define "different sides" really.

Two triangles that are coplanar will have equal normals, that is, their dot product will be 1.0 - as the dot-product decreases (from 1.0 through to -1.0) you're getting triangles with increasingly different angles between their surfaces.

A similar technique can be used to determine the sillhouette edges for shadow-volume extrusion - there will be plenty of material on this subject so go make friends with your favourite search engine [wink]

hth
Jack

##### Share on other sites
when i said sides i actually meant faces, how do you find how many faces a mesh has if you know how meny verts it has.

##### Share on other sites
For triangle lists, and assuming no degenerate triangles:
# faces (triangles) = # indices / 3

This is a pretty simple formula since each triangle has exactly three indices. Similar formulae exist for triangle strips and fans.

##### Share on other sites
There is no way to know, if you only know the number of vertices. You at least need to know what type of primitives it contains (triangle list, strip, fan, soup, etc). If it's just a list of triangles, then it's (Size / 3), if it's a strip, it's (Size - 2), and if it's a fan, it's (Size - 2) as well. If it's a soup, well then there has to be some other method of determining faces, like a list of indices. If you are using an index array with a soup of vertex, then you can use the same formulas as above, just using the size of the index array instead.

##### Share on other sites
ok this is what I do, I load a mesh with LoadMeshFromX D3D Function, which loads my mesh and gets the number of verts in it, i can later call GetIndexBuffer from the mesh (or GetVertexBuffer) to get those buffers, but how do I figure out if its a triangle strip/fan/ or else?

##### Share on other sites
Sadly, I've never worked much with the D3DXMesh class, can you tell us what exactly you're trying to do? If you just want the number of faces, you can call pkMesh->GetNumFaces(). Are you trying to rip the data out into your own class, though, so you can render things manually (basically just using the LoadMesh function as a decoder for the X files)?

##### Share on other sites

If the mesh is a closed manifold, then there's a fixed mathematical relationship that gives the number of faces in terms of the number of vertices. I can't remember what it is off the top of my head.

JB

##### Share on other sites
Are you referring to Euler's formula, which gives the relationship between the number of of faces, vertices, and edges: F+V-E=2? You'd need some way to determine the number of edges, which you might be able to induce from the types of primitives.

##### Share on other sites

Yes, euler's formula is what I was thinking of.

JB

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 9
• 9
• 9
• 46
• ### Forum Statistics

• Total Topics
631751
• Total Posts
3002077
×