Home > 05-08-Geometry > demo_3D_Points_distances.m

demo_3D_Points_distances

PURPOSE ^

% demo distanc 3D point

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% demo distanc 3D point

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% demo distanc 3D point
0002 %
0003 % Susanne Wenzel 12/17
0004 % wenzel@igg.uni-bonn.de
0005 
0006 clc
0007 close all
0008 clearvars
0009 
0010 
0011 addpath(genpath('../General-Functions'))
0012 
0013 ss = plot_init;
0014 
0015 fprintf('\n------ DEMO 3D point distances ------\n')
0016 
0017 fprintf('\nIn order to shorten the output, we display transposed vectors\n')
0018 
0019 fprintf('\nGiven: 3D points\n')
0020 X = [1,1,1]'; disp(['X = [', num2str(X'),']'])
0021 X_ = [X;1];
0022 Y = [3,1,1]'; disp(['Y = [', num2str(Y'),']'])
0023 Y_ = [Y;1];
0024 Z = [4,4,1]'; disp(['Z = [', num2str(Z'),']'])
0025 Z_ = [Z;1];
0026 
0027 figure('Color','w','Position',[50 ss(2)/3 ss(1)/3 ss(2)/2]);
0028 pltp = @(X)scatter3(X(1),X(2),X(3),'ko');
0029 plttxt = @(X,txt)text(X(1)+.1,X(2)-.1,X(3),txt);
0030 hold on
0031 pltp(X),plttxt(X,'X')
0032 pltp(Y),plttxt(Y,'Y')
0033 pltp(Z),plttxt(Z,'Z')
0034 fill3([X(1),Y(1),Z(1)],[X(2),Y(2),Z(2)],[X(3),Y(3),Z(3)],'r')
0035 xlim([0,5]),ylim([0,5]), zlim([0,5])
0036 set(gca,'CameraPosition',[ -4.3227  -28.5303   31.9206])
0037 set(gca,'CameraViewAngle',10.1830)
0038 
0039 fprintf('\n3D line through X-Y\n')
0040 L_ = calc_Pi(X_)*Y_; disp(['L = X ^ Y = [', num2str(L_'),']'])
0041 
0042 
0043 fprintf('\nDistance of Z to line L\n')
0044 d_ZL = calc_distance_3D_point_from_3D_line(Z_,L_)                           %#ok<*NOPTS>
0045 
0046 fprintf('\nDistance of Z to linesegment X-Y\n')
0047 d_Z_XY = calc_distance_3D_point_from_linesegment(Z,X,Y)
0048 
0049 fprintf('\nDefine more 3D points\n\n')
0050 T = [2.5  2.  4; ... % a point above the triangle
0051     2   0.5  0.5; ... % outside the triangle, next to one side
0052     0.5 0.5 0.5;... % outside the trinagle, next to one corner
0053     ]';
0054 
0055 for i = 1:size(T,2)
0056     disp(['T_',num2str(i),' = [', num2str(T(:,i)'),']'])
0057     pltp(T(:,i)),plttxt(T(:,i),['$T_',num2str(i),'$'])
0058     
0059     d_T_XYZ = calc_distance_3D_point_from_triangle(T(:,i),X,Y,Z);
0060     disp(['Distance of T_',num2str(i),' to line L',...
0061         num2str(d_T_XYZ)])
0062     
0063     disp('press F5 to continue')
0064     keyboard
0065 end

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