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

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

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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