Home > General-Functions > Geometry > calc_distance_3D_point_from_triangle.m

calc_distance_3D_point_from_triangle

PURPOSE ^

Abstand Punkt T und Dreieck D(X,Y,Z)

SYNOPSIS ^

function dist = calc_distance_3D_point_from_triangle(T,X,Y,Z)

DESCRIPTION ^

 Abstand Punkt T und Dreieck D(X,Y,Z)

 Usage:
   dist = calc_distance_3D_point_from_triangle(T,X,Y,Z)

   T, X, Y, Z - 3D points, euclidean
   dist       - double, shortest distance from T to triangle X-Y-Z 

 Wolfgang Förstner
 wfoerstn@uni-bonn.de 

 last changes
 Susanne Wenzel 12/17
 wenzel@igg.uni-bonn.de

 See also calc_distance_3D_point_from_3D_line, calc_distance_3D_point_from_linesegment

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Abstand Punkt T und Dreieck D(X,Y,Z)
0002 %
0003 % Usage:
0004 %   dist = calc_distance_3D_point_from_triangle(T,X,Y,Z)
0005 %
0006 %   T, X, Y, Z - 3D points, euclidean
0007 %   dist       - double, shortest distance from T to triangle X-Y-Z
0008 %
0009 % Wolfgang Förstner
0010 % wfoerstn@uni-bonn.de
0011 %
0012 % last changes
0013 % Susanne Wenzel 12/17
0014 % wenzel@igg.uni-bonn.de
0015 %
0016 % See also calc_distance_3D_point_from_3D_line, calc_distance_3D_point_from_linesegment
0017 
0018 function dist = calc_distance_3D_point_from_triangle(T,X,Y,Z)
0019 
0020 % normal of triangle
0021 V  = cross(X-Y,Z-Y);
0022 Vu = [V;0];
0023 
0024 % check geometric relation of given points
0025 f = det([[X;1] [Y;1] [Z;1] Vu])+eps;
0026 u = det([[Y;1] [Z;1] [T;1] Vu])/f;
0027 v = det([[Z;1] [X;1] [T;1] Vu])/f;
0028 w = det([[X;1] [Y;1] [T;1] Vu])/f;
0029 
0030 if u >= 0 && v >= 0 && w >= 0
0031     % foot point of T lies inside X-Y-Z
0032     % distance point plane
0033     Am = [[X;1] [Y;1] [Z;1]];
0034     A = null(Am');
0035     A = A(1:4,1);
0036     dist = abs(T'*A(1:3)+A(4))/norm(A(1:3));   % see PCV (7.99), given T_h = 1
0037     % following PCV (7.99) it should look like
0038     % dist = abs([T;1]'*A)/norm(1*A(1:3));
0039 end
0040 if u <= 0 && v >= 0 && w >= 0
0041     % foot point of T lies outside triangel X-Y-Z, but next to
0042     % line segment Y-Z
0043     dist = calc_distance_3D_point_from_linesegment(T,Y,Z);
0044 end
0045 if u >= 0 && v <= 0 && w >= 0
0046     % foot point of T lies outside triangel X-Y-Z, but next to
0047     % line segment X-Z
0048     dist = distanz_Punkt_Kante(T,X,Z);
0049 end
0050 if u >= 0 && v >= 0 && w <= 0
0051     % foot point of T lies outside triangel X-Y-Z, but next to
0052     % line segment X-Y
0053     dist = calc_distance_3D_point_from_linesegment(T,X,Y);
0054 end
0055 if u >= 0 && v <= 0 && w <= 0
0056     % foot point of T lies outside triangel X-Y-Z,
0057     % outside linesegments
0058     % but next to point X
0059     dist = norm(T-X);
0060 end
0061 if u <= 0 && v >= 0 && w <= 0
0062     % foot point of T lies outside triangel X-Y-Z,
0063     % outside linesegments
0064     % but next to point Y
0065     dist = norm(T-Y);
0066 end
0067 if u <= 0 && v <= 0 && w >= 0
0068     % foot point of T lies outside triangel X-Y-Z,
0069     % outside linesegments
0070     % but next to point Z
0071     dist = norm(T-Z);
0072 end
0073

Generated on Sat 21-Jul-2018 20:56:10 by m2html © 2005