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

Last change on this file since 243 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
RevLine 
[2]1;+
2;
[224]3; @file_comments
4; Calculate coordinates of the intersection between 2 straight lines
[133]5; or of a succession of 2 straight lines.
[2]6;
[224]7; @categories
[157]8; Utilities
[224]9;
[163]10; @param ABC1 {in}{required}{type=3d array}
[224]11; is the first array of dimension 3, number_of_pairs_of_straight_lines,
[242]12; whose each line contain the 3 parameters a, b and c of the first linear
[136]13; equation of the type ax+by+c=0
[2]14;
[163]15; @param ABC2 {in}{required}{type=3d array}
[224]16; is second array of dimension 3, number_of_pairs_of_straight_lines,
[242]17; whose each line contain the 3 parameters a, b and c of the second linear
[136]18; equation of the type ax+by+c=0
[2]19;
[224]20; @keyword FLOAT
21; To return the output as a array of real numbers instead of vectors of
[136]22; complex (by default)
[2]23;
[224]24; @returns
[136]25; 2 possibilities:
[224]26;      1) by default: it is a vector of complex whose each element is the coordinates
[133]27;                     of the intersection point of a pair of straight lines.
[242]28;      2) if FLOAT is activated, it is a array of reals of dimension 2,
[224]29;         number_of_pairs_of_straight_lines whose each row is the coordinates
[133]30;         of the intersection point of a pair of straight line.
[2]31;
[224]32; @restrictions
[242]33; If the 2 straight lines are parallel, we return coordinates
[136]34; (!values.f_nan,!values.f_nan)
[2]35;
[224]36; Beware of the precision of the machine which make
37; that calculated coordinates may not exactly verify
[136]38; equations of the pair of straight lines.
[2]39;
[224]40; @examples
[136]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
[2]47;
[224]48; @history
49; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[133]50;          10 juin 2000
51;
[224]52; @version
53; $Id$
[133]54;
[2]55;-
[231]56;
[2]57FUNCTION lineintersection, abc1, abc2, FLOAT = float
58;
[114]59;
60  compile_opt idl2, strictarrsubs
61;
[2]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
[224]77      npts = n_elements(x)
[2]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.