source: trunk/SRC/Utilities/lineintersection.pro @ 133

Last change on this file since 133 was 133, checked in by navarro, 18 years ago

english and nicer header (1)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Calculate coordinates of the intersection between 2 straight lines
8; or of a succession of 2 straight lines.
9;
10; @categories utilities
11;
12; @param abc1 {in}{required} is the first table of dimension 3, number_of_pairs_of_straight_lines,
13;         whose each line contain the 3 parameters a,b and c of the first linear
14;         equation of the type ax+by+c=0
15;
16; @param abc2 {in}{required} is second table of dimension 3, number_of_pairs_of_straight_lines,
17;         whose each line contain the 3 parameters a,b and c of the second linear
18;         equation of the type ax+by+c=0
19;
20; @keyword FLOAT To return the output as a table of real numbers instead of vectors of complex (by default)
21;
22; @returns 2 possibilities:
23;      1) by default: it is a vector of complex whose each element is the coordinates
24;                     of the intersection point of a pair of straight lines.
25;      2) if FLOAT is activated, it is a table of reals of dimension 2,
26;         number_of_pairs_of_straight_lines whose each row is the coordinates
27;         of the intersection point of a pair of straight line.
28;
29; @restrictions If the 2 straight line are parallel, we return coordinates (!values.f_nan,!values.f_nan)
30;
31; @restrictions Beware of the precision of the machine which make
32;               that calculated coordinates may not exactly verify
33;               equations of the pair of straight lines.
34;
35; @examples IDL> abc1=linearequation(complex(1,2),[3,4])
36;           IDL> abc2=linearequation(complex(1,2),[8,15])
37;           IDL> print, lineintersection(abc1, abc2)
38;           (      1.00000,      2.00000)
39;           IDL> print, lineintersection(abc1, abc2,/float)
40;                 1.00000      2.00000
41;
42; @history Sebastien Masson (smasson@lodyc.jussieu.fr)
43;          10 juin 2000
44;
45; @version $Id$
46;
47;-
48;------------------------------------------------------------
49;------------------------------------------------------------
50;------------------------------------------------------------
51FUNCTION lineintersection, abc1, abc2, FLOAT = float
52;
53;
54  compile_opt idl2, strictarrsubs
55;
56   a1 = float(reform(abc1[0, *]))
57   b1 = float(reform(abc1[1, *]))
58   c1 = float(reform(abc1[2, *]))
59   a2 = float(reform(abc2[0, *]))
60   b2 = float(reform(abc2[1, *]))
61   c2 = float(reform(abc2[2, *]))
62;
63   determinant = a1*b2-a2*b1
64   nan = where(determinant EQ 0)
65   if nan[0] NE -1 THEN determinant = !values.f_nan
66;
67   x = (b1*c2-c1*b2)/determinant
68   y = (c1*a2-a1*c2)/determinant
69;
70   if keyword_set(float) then begin
71      npts = n_elements(x)
72      res = [reform(x, 1, npts, /over), reform(y, 1, npts, /over)]
73   ENDIF ELSE res = complex(x, y)
74   return, res
75end
Note: See TracBrowser for help on using the repository browser.