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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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