15.08.2011, 15:31
I posted one a while ago but it was not very useful since it was only for 2D coords and had constant line points.
GetDistancePointLine:
Params:
Example:
Returns '243.141204' which is the correct distance from point "500.0, 800.0, 10.0" to line starting from null point with direction vector 0.5, 0.5, 0.1.
GetDistancePointLine:
pawn Код:
#define GetDistancePointLine(%0,%1,%2,%3,%4,%5,%6,%7,%8) \
floatsqroot(floatpower((%4) * ((%8) - (%2)) - (%5) * ((%7) - (%1)), 2.0) + floatpower((%5) * ((%6) - (%0)) - (%3) * ((%8) - (%2)), 2.0) + floatpower((%3) * ((%7) - (%1)) - (%4) * ((%6) - (%0)), 2.0)) / floatsqroot((%3) * (%3) + (%4) * (%4) + (%5) * (%5))
Код:
%0 - Line start position X. %1 - Line start position Y. %2 - Line start position Z. %3 - Line vector X. %4 - Line vector Y. %5 - Line vector Z. %6 - Point X. %7 - Point Y. %8 - Point Z.
pawn Код:
GetDistancePointLine(0.0, 0.0, 0.0, 0.5, 0.5, 0.1, 500.0, 800.0, 10.0);