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

Last change on this file since 371 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

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