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

Last change on this file since 413 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
RevLine 
[2]1;+
2;
[224]3; @file_comments
[133]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.
[2]7;
[224]8; @categories
9; Utilities
10;
11; @param POINT1 {in}{required}
[242]12; This is the first point of (the) straight line(s) whose we want to calculate
[136]13; equation(s)
[2]14;
[224]15; @param POINT2 {in}{required}
[242]16; This is the second point of (the) straight line(s) whose we want to calculate
[136]17; equation(s)
[2]18;
[136]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.
[133]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.
[2]23;
[224]24; @returns
25; abc is a table of dimension 3, number_of_straight_line,
[136]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
[2]28;
[224]29; @examples
[371]30;
31;   IDL> abc=linearequation(complex(1,2),[3,4])
32;   IDL> print, abc[0]*1+abc[1]*2+abc[2]
[136]33; 0.00000
[2]34;
[224]35; @history
36; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[133]37;          10 juin 2000
[2]38;
[224]39; @version
40; $Id$
[2]41;
42;-
43FUNCTION linearequation, point1, point2
[114]44;
45  compile_opt idl2, strictarrsubs
46;
[2]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)
[224]66   abc = fltarr(3, n_elements(x1))
[2]67
68   IF novertical[0] NE -1 then BEGIN
69; y=mx+p
[224]70      nele = n_elements(novertical)
[2]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
[224]77      nele = n_elements(vertical)
[2]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.