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

Last change on this file since 413 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
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:
[375]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.
[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
[371]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)
[136]45; (      1.00000,      2.00000)
[371]46;   IDL> print, lineintersection(abc1, abc2,/float)
[136]47; 1.00000      2.00000
[2]48;
[224]49; @history
50; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[133]51;          10 juin 2000
52;
[224]53; @version
54; $Id$
[133]55;
[2]56;-
[327]57FUNCTION lineintersection, abc1, abc2, FLOAT=float
[2]58;
[114]59  compile_opt idl2, strictarrsubs
60;
[2]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
[224]76      npts = n_elements(x)
[2]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.