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

Last change on this file since 375 was 375, checked in by pinsard, 16 years ago

improvements of headers (paragraphs and alignments)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 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
27;     coordinates 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;
42;   IDL> abc1=linearequation(complex(1,2),[3,4])
43;   IDL> abc2=linearequation(complex(1,2),[8,15])
44;   IDL> print, lineintersection(abc1, abc2)
45; (      1.00000,      2.00000)
46;   IDL> print, lineintersection(abc1, abc2,/float)
47; 1.00000      2.00000
48;
49; @history
50; Sebastien Masson (smasson\@lodyc.jussieu.fr)
51;          10 juin 2000
52;
53; @version
54; $Id$
55;
56;-
57FUNCTION lineintersection, abc1, abc2, FLOAT=float
58;
59  compile_opt idl2, strictarrsubs
60;
61   a1 = float(reform(abc1[0, *]))
62   b1 = float(reform(abc1[1, *]))
63   c1 = float(reform(abc1[2, *]))
64   a2 = float(reform(abc2[0, *]))
65   b2 = float(reform(abc2[1, *]))
66   c2 = float(reform(abc2[2, *]))
67;
68   determinant = a1*b2-a2*b1
69   nan = where(determinant EQ 0)
70   if nan[0] NE -1 THEN determinant = !values.f_nan
71;
72   x = (b1*c2-c1*b2)/determinant
73   y = (c1*a2-a1*c2)/determinant
74;
75   if keyword_set(float) then begin
76      npts = n_elements(x)
77      res = [reform(x, 1, npts, /over), reform(y, 1, npts, /over)]
78   ENDIF ELSE res = complex(x, y)
79   return, res
80end
Note: See TracBrowser for help on using the repository browser.