0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 
0020 
0021 
0022 
0023 
0024 
0025 
0026 
0027 
0028 
0029 clearvars
0030 clc
0031 close all
0032 
0033 addpath(genpath('../General-Functions'))
0034 
0035 fprintf('\n------ DEMO Line Through Four Lines ------\n')
0036 
0037 fprintf('\nIn order to shorten the output, we display transposed vectors\n')
0038 
0039 
0040 
0041 disp('------------- four random lines --------------')
0042 L1 = calc_Pi(rand(4,1))*randn(4,1);
0043 L2 = calc_Pi(rand(4,1))*randn(4,1);
0044 L3 = calc_Pi(rand(4,1))*randn(4,1);
0045 L4 = calc_Pi(rand(4,1))*randn(4,1);
0046 M = [L1,L2,L3,L4]                                                           
0047 disp(['rank(M) = ', num2str(rank(M))])
0048 
0049 
0050 fprintf('\ndetermine polynomial for intersecting line\n')
0051 NM = null(M'*calc_Dual);
0052 null_space_M = NM                                                           
0053 
0054 N1 = NM(:,1);
0055 N2 = NM(:,2);
0056 a = (N1-N2)'*calc_Dual*(N1-N2);
0057 b = 2*(N1-N2)'*calc_Dual*N2;
0058 c = N2'*calc_Dual*N2;
0059 coefficients = [a,b,c]                                                       
0060 rr = roots([a,b,c]);
0061 disp(['solutions: ',num2str(rr')])
0062 
0063 M1 = rr(1)*N1+(1-rr(1))*N2;
0064 M2 = rr(2)*N1+(1-rr(2))*N2;
0065 two_lines = [M1';M2'];
0066 fprintf('\ntwo lines \n')
0067 disp(['M_1 = [',num2str(M1'),']'])
0068 disp(['M_2 = [',num2str(M2'),']'])
0069 incidences = two_lines*calc_Dual*M                                          
0070 
0071 
0072 fprintf('\n------------- three random but parallel lines, one other --------------\n')
0073 
0074 D123 = [rand(3,1);0];
0075 D4 = [rand(3,1);0];
0076 
0077 L1 = calc_Pi(rand(4,1))*D123;
0078 L2 = calc_Pi(rand(4,1))*D123;
0079 L3 = calc_Pi(rand(4,1))*D123;
0080 
0081 L4 = calc_Pi(rand(4,1))*D4;
0082 L1 = L1/L1(1);
0083 L2 = L2/L2(1);
0084 L3 = L3/L3(1);
0085 L4 = L4/L4(1);
0086 M = [L1,L2,L3,L4]                                                           
0087 disp(['rank(M) = ', num2str(rank(M))])
0088 
0089 NM = null(M'*calc_Dual);
0090 null_space = NM                                                             
0091 N1 = NM(:,1);
0092 N2 = NM(:,2);
0093 a = (N1-N2)'*calc_Dual*(N1-N2);
0094 b = 2*(N1-N2)'*calc_Dual*N2;
0095 c = N2'*calc_Dual*N2;
0096 coefficients_polynomial_no_solution = [a,b,c]                               
0097 solutions = roots([a,b,c])';
0098 disp(['solutions: ',num2str(solutions)])
0099 
0100 
0101 fprintf('\n------------- three random but intersecting lines, one other --------------\n')
0102 
0103 X1 = rand(4,1);
0104 X2 = rand(4,1);
0105 
0106 
0107 L1 = calc_Pi(rand(4,1))*X1;
0108 L2 = calc_Pi(rand(4,1))*X1;
0109 L3 = calc_Pi(rand(4,1))*X1;
0110 
0111 L4 = calc_Pi(rand(4,1))*X2;
0112 M = [L1,L2,L3,L4]                                                           
0113 disp(['rank(M) = ', num2str(rank(M))])
0114 
0115 NM = null(M'*calc_Dual);
0116 nullspace = NM                                                              
0117 N1 = NM(:,1);
0118 N2 = NM(:,2);
0119 a = (N1-N2)'*calc_Dual*(N1-N2);
0120 b = 2*(N1-N2)'*calc_Dual*N2;
0121 c = N2'*calc_Dual*N2;
0122 coefficients_polynomial_no_solution = [a,b,c]                               
0123 solutions = roots([a,b,c])';
0124 disp(['solutions: ',num2str(solutions)])
0125 
0126 
0127 fprintf('\n------------- three coplanar intersecting lines, one other --------------\n')
0128 
0129 X = [1,0,0,1]';
0130 Y = [0,1,0,1]';
0131 Z = [0,0,1,1]';
0132 
0133 T = [randn(1,3),1]';
0134 
0135 disp(['Determinant should not be zero: ', num2str(det([X,Y,Z,T]))])
0136 
0137 
0138 L1 = calc_Pi(X)*Y;
0139 L2 = calc_Pi(Y)*Z;
0140 L3 = calc_Pi(Z)*X;
0141 
0142 L4 = calc_Pi(X)*T;
0143 
0144 M = [L1,L2,L3,L4]                                                           
0145 disp(['rank(M) = ', num2str(rank(M))])
0146 
0147 NM = null(M'*calc_Dual);
0148 nullspace = NM                                                              
0149 N1 = NM(:,1);
0150 N2 = NM(:,2);
0151 as = (N1-N2)'*calc_Dual*(N1-N2);
0152 bs = 2*(N1-N2)'*calc_Dual*N2;
0153 cs = N2'*calc_Dual*N2;
0154 coefficients_polynomial_no_solution = [as,bs,cs]                            
0155 solutions = roots([as,bs,cs])';
0156 disp(['solutions: ',num2str(solutions)])
0157 
0158 
0159 
0160 fprintf('\n------------- two intersecting lines, two others --------------\n')
0161 
0162 X = [-1,0,2,1]';
0163 Y = [1,0,3,1]';
0164 Z = [0,1,2,1]';
0165 T = [1,-1,3,1]';
0166 
0167 L1 = [1,0,0,0,0,0]';
0168 
0169 L2 = [0,1,0,0,0,0]';
0170 
0171 L3 = calc_Pi(X)*Y;
0172 
0173 L4 = calc_Pi(Z)*T;
0174 
0175 M = [L1,L2,L3,L4]                                                           
0176 disp(['rank(M) = ', num2str(rank(M))])
0177 
0178 NM = null(M'*calc_Dual);
0179 null_space = NM                                                             
0180 N1 = NM(:,1);
0181 N2 = NM(:,2);
0182 a = (N1-N2)'*calc_Dual*(N1-N2);
0183 b = 2*(N1-N2)'*calc_Dual*N2;
0184 c = N2'*calc_Dual*N2;
0185 coefficients_polynomial = [a,b,c]                                           
0186 solutions = roots([a,b,c])';
0187 disp(['solutions: ',num2str(solutions)])
0188 
0189 M1 = rr(1)*N1+(1-rr(1))*N2;
0190 M2 = rr(2)*N1+(1-rr(2))*N2;
0191 two_lines = [M1';M2'];
0192 fprintf('\ntwo lines \n')
0193 disp(['M_1 = [',num2str(M1'),']'])
0194 disp(['M_2 = [',num2str(M2'),']'])
0195 incidences = two_lines*calc_Dual*M