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

Last change on this file since 227 was 224, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • 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
38; Sebastien Masson (smasson\@lodyc.jussieu.fr)
39;          10 juin 2000
40;
41; @version
42; $Id$
43;
44;-
45;------------------------------------------------------------
46;------------------------------------------------------------
47;------------------------------------------------------------
48FUNCTION linearequation, point1, point2
49;
50  compile_opt idl2, strictarrsubs
51;
52
53   if size(point1, /type) EQ 6 OR size(point1, /type) EQ 9 then begin
54      x1 = float(point1)
55      y1 = imaginary(point1)
56   ENDIF ELSE BEGIN
57      x1 = float(reform(point1[0, *]))
58      y1 = float(reform(point1[1, *]))
59   ENDELSE
60
61   if size(point2, /type) EQ 6 OR size(point2, /type) EQ 9 then begin
62      x2 = float(point2)
63      y2 = imaginary(point2)
64   ENDIF ELSE BEGIN
65      x2 = float(reform(point2[0, *]))
66      y2 = float(reform(point2[1, *]))
67   ENDELSE
68
69   vertical = where(x1 EQ x2)
70   novertical = where(x1 NE x2)
71   abc = fltarr(3, n_elements(x1))
72
73   IF novertical[0] NE -1 then BEGIN
74; y=mx+p
75      nele = n_elements(novertical)
76      m = (y2[novertical]-y1[novertical])/(x2[novertical]-x1[novertical])
77      p = (x2[novertical]*y1[novertical]-y2[novertical]*x1[novertical])/(x2[novertical]-x1[novertical])
78      abc[*, novertical] = [reform(-m, 1, nele), replicate(1, 1, nele), reform(-p, 1, nele)]
79   ENDIF
80   IF vertical[0] NE -1 then BEGIN
81; x=ny+p
82      nele = n_elements(vertical)
83      n = (x2[vertical]-x1[vertical])/(y2[vertical]-y1[vertical])
84      p = (y2[vertical]*x1[vertical]-x2[vertical]*y1[vertical])/(y2[vertical]-y1[vertical])
85      abc[*, vertical] = [replicate(1, 1, nele), reform(-n, 1, nele), reform(-p, 1, nele)]
86   ENDIF
87
88   return, abc
89end
Note: See TracBrowser for help on using the repository browser.