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

Last change on this file since 136 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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