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

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

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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