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

Last change on this file since 227 was 224, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

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