# [Cross post because this didn't seem to get any response in the math forum] - CSG

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

## Recommended Posts

Ok, I'm a bit dumbfounded here. I've got 2 brushes, "A" and "B", each containing a series of convex polygons. If I want to subtract brush "A" from brush "B", what's the best way to calculate the new triangles to be rendered? I was looking through the unreal editor to see how the intersections worked. It seems as if they're never actually modifying the brushes, but rather just storing the information for the brush, and then calculating the triangles to be rendered each time you do a new subtract / add. I was thinking something like this:

struct Polygon
{
Vert* Verts;
int   NumVerts;
};

struct Brush
{
Polygon* Polys;
int      NumPolys;
};
void SubtractBrush(Brush* pBrush, Brush* pBrush2,Vert* pVerts);
{
int iFilled = 0;
for(int i = 0; i < pBrush->NumPolys; i++)
{
Polygon* poly = &pBrush.Polys;
for(int iVerts = 0; i Verts < poly->NumVerts; iVerts++)
if(!PointIsInBrush(poly->Verts[iVerts],pBrush2)
Verts[iFilled++] = poly->Verts[iVerts];
}
}

That would effectively create the 'new' brush, though of course I'm not 100% sure how to calculate the right order to render these vertices in to. Well, not exactly. I suppose i'd need to also create vertices at the point of intersection along the edges when they crossed into the subtractive brush, too. That further complicates things, but i'd be happy just knowing I had the correct vertices, much less having the correct triangles.

##### Share on other sites

http://www.3dtechdev.com/tutorials/illegalgeometry/illegalgeometrytut.html

-=[ Megahertz ]=-

##### Share on other sites
But some polys of the brushes could intersect.. then you need to _clip_ the brushes together first..

##### Share on other sites
right, that was my second addendum...polys that intersect one another, as new vertices would need to be created.

I'm reading through this paper, though, it seems to be about what I'm looking for. Thanks.