1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; |
---|
6 | ; @file_comments |
---|
7 | ; Calculate coordinates of the intersection between 2 straight lines |
---|
8 | ; or of a succession of 2 straight lines. |
---|
9 | ; |
---|
10 | ; @categories |
---|
11 | ; Utilities |
---|
12 | ; |
---|
13 | ; @param ABC1 {in}{required}{type=3d array} |
---|
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 |
---|
16 | ; equation of the type ax+by+c=0 |
---|
17 | ; |
---|
18 | ; @param ABC2 {in}{required}{type=3d array} |
---|
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 |
---|
21 | ; equation of the type ax+by+c=0 |
---|
22 | ; |
---|
23 | ; @keyword FLOAT |
---|
24 | ; To return the output as a array of real numbers instead of vectors of |
---|
25 | ; complex (by default) |
---|
26 | ; |
---|
27 | ; @returns |
---|
28 | ; 2 possibilities: |
---|
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. |
---|
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 |
---|
33 | ; of the intersection point of a pair of straight line. |
---|
34 | ; |
---|
35 | ; @restrictions |
---|
36 | ; If the 2 straight line are parallel, we return coordinates |
---|
37 | ; (!values.f_nan,!values.f_nan) |
---|
38 | ; |
---|
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. |
---|
43 | ; |
---|
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 |
---|
51 | ; |
---|
52 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
53 | ; 10 juin 2000 |
---|
54 | ; |
---|
55 | ; @version $Id$ |
---|
56 | ; |
---|
57 | ;- |
---|
58 | ;------------------------------------------------------------ |
---|
59 | ;------------------------------------------------------------ |
---|
60 | ;------------------------------------------------------------ |
---|
61 | FUNCTION lineintersection, abc1, abc2, FLOAT = float |
---|
62 | ; |
---|
63 | ; |
---|
64 | compile_opt idl2, strictarrsubs |
---|
65 | ; |
---|
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 |
---|
85 | end |
---|