Assuming you know about the cross product between two vectors, here's how it goes:
- For a polygon in the V1 mesh, calculate the plane that goes through this polygon. I'm assuming triangular polygons here, if the polys are quads, this methot will be a little off, but not by much.
If v1 is one vertex in the polygon (say, the first one), v2 the second and v3 the third, you can calculate the equation of this plane: ((v2-v1) crossproduct (v2-v3)) * X = ((v2-v1) crossproduct (v2-v3) )*v1
- The line through the V3 vertex along its normal can be represented by X=t*n + v, in which t is a scalar variable, n is the normal of the vertex, and v is the vertex itself
- Now you can determine the point where this line intersects the plane calculated in step 1, by substituting the X in 1) by the formula for X in 2)
- You've got the intersection point, let's call it X again. X is now a vertex, not a plane or a line. But does X lie within the borders of the polygon? Here's how you calculate this (again the crossproduct trick): calculate the crossproduct between the vectors (v2-v1) and (X-v2). The result is a vector perpendicular to the polygon. It can either point "outward" or "inward" - you can determine this by calculating the dot product of this resulting vector with the normal at v2. A positive result means pointing outward, a negative result means pointing inward.
Remember "positive" or "negative"
Now do the same between the vectors (v3-v2) and (X-v3) and the vectors (v1-v3) (X-v1).
If all results are "positive" or all results are "negative", the intersection point lies within the borders of the polygon. You've found the right point.
And if there's a mixture between "positive" and "negative", the intersection point lies outside the polygon edges, so you'll have to find another polygon that matches.
Note: if the polygon is a quad, you'll have to calculate (v4-v3)x(X-v4) and (v1-v4)x(X-v1), not (v1-v3)x(X-v1).
This method should work for all closed meshes. Open meshes have a potential problem - the line through a normal of the source mesh might not intersect ANY polygon in the target mesh. In that case, it's probably best to add this vertex to a list of exceptions, and then try calculating its best delta from the deltas of the surrounding vertices.
I hope I haven't confused you too much....
The pen is mightier than the sword. But if you literally
want to have some impact, use a typewriter
My
gallery My
freestuff