I am currently trying to implement a laidlaw-like CSG algorithm.
The essential task is to split polygons so they dont intersect.
Only thing for me left to do now is to split the polygons, on paper I know how to do it, in code it is a little more difficult.
Let's sag we have a single triangle, of course lying on a plane.
Within the triangle there is a (intersection) segment, not touching the boundary or a vertex.
I need two things now:
- An algorithm to get an orthogonal Segment to the existing one so they are forming a cross. I'm doing things a little different than in the Laidlaw-Paper (I didn't understand completely), which is why I need the orthogonal segment.
- An algorithm to determine if a point is on one side of the segment (or infinite line that goes through the segment points), or the other one.
Remember: EVERY point is on the triangle plane. So when I say orthogonal I don't mean pointing out of the plane.
For the last one I already did something but I am not sure its working correctly, it passed the view test I have made, but the results when applying it are a bit confusing.
public static double WichSide(Segment3D seg, Vector3db P)
{
Vector3db cp1 = Vector3db.Cross(seg.P1 - seg.P0, P - seg.P0);
return Vector3db.Dot(new Vector3db(1,1,1), cp1);
}
I thought this function gave some number with a negative sign if the point P is on the right, and a positive one if its on the left.
The class Vector3db is pretty similar to any Vector3 class there is.
Now please, I am not good at math, it was took me weeks to get where I am and I still don't understand every algorithm I am using (I try), so try to keep your answers as simple as possible :sigh:
Thanks in advance guys,
Jan
Addition:
Well apparently the only thing unclear was my defintion of segment:
Like in most 3D-Application I am refering to a line segment here which is defined by two three-dimensional points. My structure does not really contain anything else, other than calculating the line-segment's direction.
So in short:
- There is a plane containing a triangle.
- Within this triangle there is a line-segment from P0 to P1
- What I want is an orthognal segment to the line-segment P0-P1.
- Every point of this orthogonal segment has to lie (like every vertex from the triangle and the existing line-segment) on the triangle plane.
I hope this confuses you less, and you have to excuse. I am not really familiar with all the correct mathematical terms in English.
Oh and yes, my Vector class contains everything needed, like cross product, dot product, multiplication with a scalar and the proper operators.
http://imageupload.org/pt-1212944275937.html - Here is a drawing that should help you understand