Orthognal Segments on a Triangle Plane

Trollfest 101 Jan 07, 2011 at 18:07

Okay, after posting this on Code Project I realized this must be the better place to ask.

Heres my problem:
I try to implement a Laidlaw-like set of CSG-Operations.
I know (on paper) how to split the triangles, but it gets a bit difficult in code.

I have an intersection Segment on a triangle (and of course on it’s triangle plane) that goes from one boundary, to another one.
What I want is an orthognal Segment to the exisisting one, not orthogonal in the sense of pointing outside of the triangle, I’d like the segments to cross like this:

       | (This segment is supposed to go through the middle of the other one)

I need this to determine on which side some points (as well lying on the triangle plane are).

My algorithm so far for testing the side is:

        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 made some tests that suggested the algorithm works fine, but I’m not entirely sure. In this algorithm it (should) return a negatively signed double if the point is one the left and a positive signed double if its one the right.

PS: When I say segment in terms of determining the side, I actually mean a line that goes through the segment points.

I’m not particulary good at math, so please go easy on the explanation if you have a solution. Code or pseudo code would be appreciated.

Thanks in advance guys :)

1 Reply

Please log in or register to post a reply.

Reedbeta 167 Jan 07, 2011 at 18:45

If everything you’re concerned with is in the plane of the triangle, then you should use the triangle’s normal vector to construct the perpendicular vector. That is, your cp1 should be cross(seg.P1 - seg.P0, normal). Then calculate dot(P - seg.P0, cp1), and the result will be positive or negative depending on which side of the original segment P is. In fact, if you normalize cp1, then the dot product will be the actual distance (measured perpendicularly to the segment).