c# - Finding the distance of a point from a triangle in 3d space -


imagine surface of triangle in cartesian space. how can find distance of given point surface of triangle?

point 1: [ 30, 24, 22 ]
point 2: [ 35, 13, 19 ]
point 3: [ 21, 29, 85 ]

in case, how far point [ 40, 25, 77 ] surface of triangle defined above?

or - formula determine distance?

i assume mean minimal distance. otherwise, distance changes depending on point on triangle pick. see that, draw triangle on table , hold pen above it.

the short answer is, find minimal distance, need build matrix 1 point per column, so:

    [ 30 35 21 ] = [ 24 13 29 ]     [ 22 19 85 ] 

and read about projections details. if has been while since studied kind of stuff, don't intimidated. isn't rocket science (actually, maybe in intro rocket science), take investment understand. along, i'll mention bit theory first, , talk implementation.

to give intuition, hold on pen.

lets start easiest case: minimal distance, hold pen perpendicular table, end of pen in triangle somewhere. picture point tip of pen. proved point in triangle closest point projection of point onto space defined 3 points in triangle. in other words, other end of pen. other point in triangle must have distance longer pen length.

now lets @ complication. suppose point want not "above" triangle, rather side somewhere. say, off of surface of table altogether. in case, point in triangle closest point either 1 of 3 points themselves, or point on 3 line segments connecting 3 initial points.

now implementation: skinny is, if can use simple library linear algebra, save lot of grief. hardest step inverting matrix, , while inverting 3x3 matrices easy, can complicated when points co-linear (i.e., think 3 points aligned), when magnitudes different (i.e., think of long skinny triangle), etc.

you write problem-specific algorithm problem, given 3x3, @ end of day need solve projection system, algorithm doing same math on wikipedia page. may end rediscovering linear algebra, sure way waste lot of time.

my last implementation suggestion check keyword "projection" in gaming or 3d libraries. if lucky there function can call. otherwise decent clr linear algebra library, build matrix, , entire computation efficiently , in 100 lines of code or so.


Comments