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

Last change on this file since 277 was 242, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers + replace some message by some report

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