How would tesselation work ? the line segments are in 3D… all triangulation algorithms are in 2D.. would you elaborate more ?
Ray to Octree Intersection for boolean geometry
For a first step, it would be nice to visualize the intersection segments as lines. You can verify if they whole intersection path shows up already.
@Joejl
Yes and then how would I tesselate them ?
AhmedSaleh said:
How would tesselation work ? the line segments are in 3D… all triangulation algorithms are in 2D.. would you elaborate more ?
Any triangle is flat, so you could project it to the normal plane to turn it 2D.
Though, personally i stick at 3D - working in 2D does not make the problem easier.
Thinking about it, i have this idea:

Every side of the segment has to connect to a triangle vertex.
Every edge of the triangle has to connect to one vertex of the segment.
… hardest part seems to avoid edge crossings…
…better idea, maybe:
Every side of the line segment has to connect to one triangle edge to form a quad (which we triangulate later).
We pick the triangle edge which is the most contained in the half space defined by the segment.

picture shows how to find the best edge for the blue quad.
One edge remains unconnected, so we connect it to the line end which connects to two different edges. We get the final orange triangle.
Seems nice, but i'm not sure if it works for all cases.
Looks very complicated. I surrender ? Thanks for your help.
I got the intersection, but can't get the inside outside or how to tesselate at all.
I got it working at least the blue triangles are drawn now, seems the triangle to triangle intersect check was a flaw


but I get broken rectangles behind
current code, please check it
while (!stack.empty())
{
cg::Octant* node = stack.top();
stack.pop();
if (box_box_intersect(musa::triangle_bounding_box(triB), node->region))
{
auto vertices = node->faces;
for (size_t a = 0; a < vertices.count; a += 3)
{
musa::Triangle triA{ vertices[a], vertices[a + 1], vertices[a + 2] };
musa::Intersection_Segments sgs = musa::triangle_triangle_coplanar_intersection(triA, triB);
mn::buf_push(self->modelIntersection.points, sgs.segments[0].start);
mn::buf_push(self->modelIntersection.points, sgs.segments[0].end);
mn::buf_push(self->modelIntersection.points, triB.p0);
mn::buf_push(self->modelIntersection.points, triB.p1);
mn::buf_push(self->modelIntersection.points, triB.p2);
}
for (auto& n : node->octants)
{
if (n == nullptr)
continue;
stack.push(n);
}
}
}
I fomulated and I get this now


while (!stack.empty())
{
cg::Octant* node = stack.top();
stack.pop();
if (box_box_intersect(musa::triangle_bounding_box(triB), node->region))
{
auto vertices = node->faces;
mn::buf_push(self->modelIntersection.points, triB.p0);
mn::buf_push(self->modelIntersection.points, triB.p1);
mn::buf_push(self->modelIntersection.points, triB.p2);
for (size_t a = 0; a < vertices.count; a += 3)
{
musa::Triangle triA{ vertices[a], vertices[a + 1], vertices[a + 2] };
musa::Intersection_Segments sgs = musa::triangle_triangle_intersection(triA, triB);
mn::buf_push(self->modelIntersection.points, sgs.segments[0].start);
mn::buf_push(self->modelIntersection.points, sgs.segments[0].end);
}
for (auto& n : node->octants)
{
if (n == nullptr)
continue;
stack.push(n);
}
}
Now I get it working, I think I need the in/out side test…
I'm doing the intersection into two iterations..
auto tri_mesh_a = cg::trimesh_from_indexed_mesh(sphere_indexed_mesh);
auto tri_mesh_b = cg::trimesh_from_indexed_mesh(cube_indexed_mesh);
auto octree_a = cg::octree_from_mesh(tri_mesh_a);
auto octree_b = cg::octree_from_mesh(tri_mesh_b);
std::stack < cg::Octant*> stack;
int num_indices = 0;
std::vector<musa::Intersection_Points> segm;
std::vector<std::vector<Point_>> polygon;
for (size_t i = 0; i < tri_mesh_a.vertices.count; i+=3)
{
musa::Triangle triB{ tri_mesh_a.vertices[i], tri_mesh_a.vertices[i + 1], tri_mesh_a.vertices[i + 2] };
stack.push(octree_b.root);
while (!stack.empty())
{
cg::Octant* node = stack.top();
stack.pop();
if (box_box_intersect(musa::triangle_bounding_box(triB), node->region))
{
auto vertices = node->faces;
mn::buf_push(self->modelIntersection.points, triB.p0);
mn::buf_push(self->modelIntersection.indices, num_indices++);
mn::buf_push(self->modelIntersection.points, triB.p1);
mn::buf_push(self->modelIntersection.indices, num_indices++);
mn::buf_push(self->modelIntersection.points, triB.p2);
mn::buf_push(self->modelIntersection.indices, num_indices++);
for (auto& n : node->octants)
{
if (n == nullptr)
continue;
stack.push(n);
}
}
}
}
for (size_t i = 0; i < tri_mesh_b.vertices.count; i += 3)
{
musa::Triangle triB{ tri_mesh_b.vertices[i], tri_mesh_b.vertices[i + 1], tri_mesh_b.vertices[i + 2] };
stack.push(octree_a.root);
while (!stack.empty())
{
cg::Octant* node = stack.top();
stack.pop();
if (box_box_intersect(musa::triangle_bounding_box(triB), node->region))
{
auto vertices = node->faces;
for (size_t a = 0; a < vertices.count; a += 3)
{
musa::Triangle triA{ vertices[a], vertices[a + 1], vertices[a + 2] };
if (musa::triangle_triangle_intersection_check(triA, triB))
{
mn::buf_push(self->modelIntersection.points, triB.p0);
mn::buf_push(self->modelIntersection.indices, num_indices++);
mn::buf_push(self->modelIntersection.points, triB.p1);
mn::buf_push(self->modelIntersection.indices, num_indices++);
mn::buf_push(self->modelIntersection.points, triB.p2);
mn::buf_push(self->modelIntersection.indices, num_indices++);
}
}
for (auto& n : node->octants)
{
if (n == nullptr)
continue;
stack.push(n);
}
}
}
}
