Depending on where the point is, it could be closest to a vertex, an edge, or a plane. You need to figure out which it is before you can calculate the distance.
To find the distance from a line to a point, where the point is p, and the line is defined by vertex1 and vertex2:
va = vertex2 - vertex1;
vb = p - vertex1;
distance = Length(vb-va*(va*vb)/LengthSquared(va));
(va*vb is dot product)
Distance between a point and a rectangular prism
Ok thank you all for the help and formulas. I''m gonna try what Basiror suggested, it''s simple enough and it should work. If it doesn''t then I guess I''ll be back here

I hate signatures.
i think i found an easier method
check if the point projected onto the plane is inside the polygon if not
create a plane perpendicular to the plane
generate its normal
project the point onto each plane and find out which projected point has the closes distance to he original point
then take this point and project it onto the plane and check whether it lies on an edge
if it doesn t project the already projected point onto the other planes which you have generated and check again
1st projected point latest projected point
and choose the edge/plane with the shortest distance
now the point should be the vertex of one of your corners
just get the distance between the original point and the result of the 1st projection or if the 1st failed of the second
and you don t need more than 2 projections to find the shortest result
this works precise and very fast
good luck
check if the point projected onto the plane is inside the polygon if not
create a plane perpendicular to the plane
generate its normal
project the point onto each plane and find out which projected point has the closes distance to he original point
then take this point and project it onto the plane and check whether it lies on an edge
if it doesn t project the already projected point onto the other planes which you have generated and check again
1st projected point latest projected point
and choose the edge/plane with the shortest distance
now the point should be the vertex of one of your corners
just get the distance between the original point and the result of the 1st projection or if the 1st failed of the second
and you don t need more than 2 projections to find the shortest result
this works precise and very fast
good luck
http://www.8ung.at/basiror/theironcross.html
i am sorry you may not perform the second to-plane projection
if the first fails get the distance between the vertices of the edge and take the shorter one
if the first fails get the distance between the vertices of the edge and take the shorter one
http://www.8ung.at/basiror/theironcross.html
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement