source: trunk/SRC/Utilities/linearequation.pro @ 133

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

english and nicer header (1)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Calculate a linear equation of the type ax+by+c=0
8; thanks to coordinates of 2 points.
9; comment: we can have a table with pairs of points.
10;
11; @categories utilities
12;
13; @param point1 {in}{required} This is the first point of(the) straight
14; line(s) whose we want to calculate equation(s)
15;
16; @param point2 {in}{required} This is the second point of(the) straight
17; line(s) whose we want to calculate equation(s)
18;
19;    There is 2 possibilities:
20;      1) point is a complex or a table ofcomplex, where each element is the coordinates of the point.
21;      2) point is a table of real of dimension 2,number_of_straight_line.
22;         For each row of the table, we have coordinates of the point.
23;
24; @returns abc is a table of dimension 3, number_of_straight_line,
25;          where for each lign of the table we obtain the 3 parameters
26;          a, b and c of the linear equation ax+by+c=0
27;
28; @examples IDL> abc=linearequation(complex(1,2),[3,4])
29;           IDL> print, abc[0]*1+abc[1]*2+abc[2]
30;           0.00000
31;
32; @history Sebastien Masson (smasson@lodyc.jussieu.fr)
33;          10 juin 2000
34;
35; @version $Id$
36;
37;-
38;------------------------------------------------------------
39;------------------------------------------------------------
40;------------------------------------------------------------
41FUNCTION linearequation, point1, point2
42;
43  compile_opt idl2, strictarrsubs
44;
45
46   if size(point1, /type) EQ 6 OR size(point1, /type) EQ 9 then begin
47      x1 = float(point1)
48      y1 = imaginary(point1)
49   ENDIF ELSE BEGIN
50      x1 = float(reform(point1[0, *]))
51      y1 = float(reform(point1[1, *]))
52   ENDELSE
53
54   if size(point2, /type) EQ 6 OR size(point2, /type) EQ 9 then begin
55      x2 = float(point2)
56      y2 = imaginary(point2)
57   ENDIF ELSE BEGIN
58      x2 = float(reform(point2[0, *]))
59      y2 = float(reform(point2[1, *]))
60   ENDELSE
61
62   vertical = where(x1 EQ x2)
63   novertical = where(x1 NE x2)
64   abc = fltarr(3, n_elements(x1))
65
66   IF novertical[0] NE -1 then BEGIN
67; y=mx+p
68      nele = n_elements(novertical)
69      m = (y2[novertical]-y1[novertical])/(x2[novertical]-x1[novertical])
70      p = (x2[novertical]*y1[novertical]-y2[novertical]*x1[novertical])/(x2[novertical]-x1[novertical])
71      abc[*, novertical] = [reform(-m, 1, nele), replicate(1, 1, nele), reform(-p, 1, nele)]
72   ENDIF
73   IF vertical[0] NE -1 then BEGIN
74; x=ny+p
75      nele = n_elements(vertical)
76      n = (x2[vertical]-x1[vertical])/(y2[vertical]-y1[vertical])
77      p = (y2[vertical]*x1[vertical]-x2[vertical]*y1[vertical])/(y2[vertical]-y1[vertical])
78      abc[*, vertical] = [replicate(1, 1, nele), reform(-n, 1, nele), reform(-p, 1, nele)]
79   ENDIF
80
81   return, abc
82end
Note: See TracBrowser for help on using the repository browser.