#### Archived

This topic is now archived and is closed to further replies.

# Getting the profile of an object...

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

## Recommended Posts

Is there a method of finding the area of the profile of a 3d object? I mean, if I take the object and flatten it, can I find the area of that object? I can do it with boxes, but trying to do it with more vertices than 8... I have no clue. Is there a function within DirectX that can do this? Does anyone know of a tutorial that includes info about this? Can anyone give me hints to send me on the right direction? If so, thanks.

##### Share on other sites
i can think of one method that should work but it might not be as fast or as accurate as you need and it''s kinda off the wall.

the idea is to first find the bounding rectangle of the 3D object on the plane you''re going to flatten it against and calculate this rectangle''s area. then project each of the 3D object''s triangles (i''m assuming a mesh of triangles here) onto that same plane and using the same projection matrix as used to get the bounding rectangle. that will convert each triangle of the 3D object into a triangle and/or line on the plane. i''m also assuming the plane still lies in 3D at this point. then transform the bounding rectangle and the 3D flattened triangles into a 2D coordinate system that may be used for graphics drawing purposes. draw the bounding rectangle as white onto a bitmap that has the same dimensions as the bounding rectangle as measured in your 2D drawing coordinate system. then draw each flattened triangle as black onto the same bitmap. then traverse through the bitmap and count the number of black pixels. the ratio of that number to the total number of pixels in the bitmap should give you a number that can then be multiplied against the area of the bounding rectangle to give you an estimate of the 3D object''s projected area. the more pixels there are in the bitmap, the more accurate the number will be.

##### Share on other sites
Plotting the pixels to an image would probably be too time consuming. What I''m doing now is: copy the bounding box, rotate it so that the facing I want is along the z axis, remove the z values from its vertices, find the enclosing rectangle''s area, find the area of the triangles (and two rectangles) that are on the outside of the bounding box but within the enclosing rectangle, and subtracting those from the enclosing area. Now trying do this same thing with more than 8 vertices is bogling my mind. I might try to figure out how to determine which vertices are on the outside of the object and then use trapazoids of those vertices and the outside of the enclosing rectangle...

##### Share on other sites
Ok, I think this would work, correct me if I am wrong someone.

Im assuming the object is built of triangles, so here is some pseudo code:

tris[]; // triangle struct/object arraytotArea = 0.0;for(int u = 0; u < num_triangles; u++){	totArea += triArea(tris[u]);}for(int k = 0; k < (num_triangles-1); k++){	for(int l = (k+1); l < num_triangls; l++)	{		totArea -= intersectionArea(tris[k], tris[l]);	}}

The triArea() function gets the total area of a single triangle (you can for example use the cross product).

The intersectionArea() function gets the area where two of the triangle intersects. This is a bit more tricky to calculate, and there are probably several ways to do it. But by calculating which edge lines that intersect, and if the points in one triangle lies within or outside the other (and vice versa), you can find out what kind of intersection it is, and its corners. If, for example, there is more than 2 intersection points then the intersection area is either a triangle or a convex polygon that can be divided into triangles.

Hope that helps!

[edited by - Jesper T on October 7, 2003 4:21:29 PM]

• 32
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631352
• Total Posts
2999483
×