xpoint

PURPOSE ^

gives the crosspoint between 2 lines (AB) and (CD)

SYNOPSIS ^

function z = xpoint(A,B,C,D)

DESCRIPTION ^

 gives the crosspoint between 2 lines (AB) and (CD)

 try:
  A=1+10*i; B = 9+i; C = 10+10*i; D = 1;
  % Plot the lines
  plot(real([A B]),imag([A B]));
  hold on;
  plot(real([C D]),imag([C D]));
  % Plot intersection points
  plot(z,'ro');
  hold off


 $Id: xpoint.m,v 1.1 2004/05/12 16:22:59 dalai Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % gives the crosspoint between 2 lines (AB) and (CD)
0002 %
0003 % try:
0004 %  A=1+10*i; B = 9+i; C = 10+10*i; D = 1;
0005 %  % Plot the lines
0006 %  plot(real([A B]),imag([A B]));
0007 %  hold on;
0008 %  plot(real([C D]),imag([C D]));
0009 %  % Plot intersection points
0010 %  plot(z,'ro');
0011 %  hold off
0012 %
0013 %
0014 % $Id: xpoint.m,v 1.1 2004/05/12 16:22:59 dalai Exp $
0015 
0016 function z = xpoint(A,B,C,D)
0017 
0018 L1_x1 = real(A);
0019 L1_y1 = imag(A);
0020 L1_x2 = real(B);
0021 L1_y2 = imag(B);
0022 L2_x1 = real(C);
0023 L2_y1 = imag(C);
0024 L2_x2 = real(D);
0025 L2_y2 = imag(D);
0026 
0027 % Compute several intermediate quantities
0028 Dx12 = L1_x1-L1_x2;
0029 Dx34 = L2_x1-L2_x2;
0030 Dy12 = L1_y1-L1_y2;
0031 Dy34 = L2_y1-L2_y2;
0032 Dx24 = L1_x2-L2_x2;
0033 Dy24 = L1_y2-L2_y2;
0034 
0035 % Solve for t and s parameters
0036 ts = [Dx12 -Dx34; Dy12 -Dy34] \ [-Dx24; -Dy24];
0037 
0038 % Take weighted combinations of points on the line
0039 P = ts(1)*[L1_x1; L1_y1] + (1-ts(1))*[L1_x2; L1_y2];
0040 Q = ts(2)*[L2_x1; L2_y1] + (1-ts(2))*[L2_x2; L2_y2];
0041 
0042 z = P(1)+i*P(2);

Generated on Sun 15-Aug-2004 22:13:10 by m2html © 2003