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

Last change on this file since 153 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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