Math “expert” wanted… Algorithm for finding line of two crossing areas
-
I’m going to create a shape-class containing a lot of flat polygon areas. I will make it possible to subtract one shape from another and then I need an algorithm to se if two polygon-areas in the 3D-space crosses each other, and if in which line the crossing is. I see there should bee some kind of linear algebra calculations but I do not really know how to start constructing my c++ shape classes. :doh: _____________________________ ...and justice for all APe
-
I’m going to create a shape-class containing a lot of flat polygon areas. I will make it possible to subtract one shape from another and then I need an algorithm to se if two polygon-areas in the 3D-space crosses each other, and if in which line the crossing is. I see there should bee some kind of linear algebra calculations but I do not really know how to start constructing my c++ shape classes. :doh: _____________________________ ...and justice for all APe
Well, hail there again. Why don't you stick to one thread? Anyway, you sholdn't be a math "expert" to solve this one, but you have to know basics of geometry at least. I'll give you solution for intersection bitween line and plane, the rest you can do yourself. We have three points and a normal vector (N). The equation of a plane is Ax+By+Cz+D=0. We have two points P1 and P2. The equation of a line is P(t)=P1+t*Pd where Pd=(P2-P1), t>0. To determine if there is an intersection with the plane, substitute for P(t) into the plane equation and get A(P1x+t*Pdx)+B(P1y+t*Pdy)+C(P1z+t*Pdz)+D=0, which yields t = -(Dot(N,P1)+D)/Dot(N,Pd). Now find divisor Vd=Dot(N, Pd), if Vd=0 then the line is parallel to the plane and if Vd>0 then the normal N of the plane is pointing away from the ray (that can be useful for one-sided faces). Now we can find t, if t<0 then the line intersects the plane behind origin, i.e. no intersection of interest, otherwise we can put t in the equation of a line to find intersection point. Enjoy.
-
Well, hail there again. Why don't you stick to one thread? Anyway, you sholdn't be a math "expert" to solve this one, but you have to know basics of geometry at least. I'll give you solution for intersection bitween line and plane, the rest you can do yourself. We have three points and a normal vector (N). The equation of a plane is Ax+By+Cz+D=0. We have two points P1 and P2. The equation of a line is P(t)=P1+t*Pd where Pd=(P2-P1), t>0. To determine if there is an intersection with the plane, substitute for P(t) into the plane equation and get A(P1x+t*Pdx)+B(P1y+t*Pdy)+C(P1z+t*Pdz)+D=0, which yields t = -(Dot(N,P1)+D)/Dot(N,Pd). Now find divisor Vd=Dot(N, Pd), if Vd=0 then the line is parallel to the plane and if Vd>0 then the normal N of the plane is pointing away from the ray (that can be useful for one-sided faces). Now we can find t, if t<0 then the line intersects the plane behind origin, i.e. no intersection of interest, otherwise we can put t in the equation of a line to find intersection point. Enjoy.
va`Lery wrote: Why don't you stick to one thread? Well no excuses. I Rebuilded the question… I’m not bad at either math or c++ but it’s the thing hat implement the algostuff into code that, for me is difficult. Small problems with both of them (math and c++) makes things hard for me. Thanks _____________________________ ...and justice for all APe