Reputation: 694
Here's a simplified version of my triangle object and related objects:
class line{
public:
double x1;
double y1;
double x2;
double y2;
}
class vertex{
public:
double x;
double y;
double z;
};
class triangle{
vertex a;
vertex b;
vertex c;
public:
line *intersection(double z_axis){
line *l = new line;
//intersection code here
return l;
}
};
What I need to happen is for the intersection function to return the line where the triangle and the plane parallel to the x and y axis at the given z axis. All the sample code I've looked at either assumes having a force normal or returns doesn't return quite what I need. I'd really appreciate some insight on how to go about doing this in an optimal way. I'm having trouble making sense of the Plane-Plane intersection formal math solutions.
Thanks in advance,
Max
Upvotes: 0
Views: 1592
Reputation: 3029
you should handle different situations:
1) there is no intersection. (for each vertex: z_axis > vertex.z) or (for each vertex: z_axis < vertex.z)
2) the triangle lies in the z=z_axis plane (for each vertex: z_axis = vertex.x). This is awkward for doubles but 0 or some powers of two or some nice binary fractions are represented precisely.
3) one vertex (let's call it P) is below and two vertices (Q, R) are above the z=z_axis plane (or vice versa)
here you'll be able to find the intersections. Your problem will be broken down to find intersection of line PQ and PR with the plane z=z_axis.
4) one or two vertices lie on the z=z_axis plane.
The intersections here are trivial, but they may still be computed the same way as in point 3.
Is it clear? You may start implementing...
Upvotes: 1