source: trunk/SRC/ToBeReviewed/UTILITAIRE/linearequation.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME: linearequation
6;
7; PURPOSE:calcule une equation de droite du type ax+by+c=0 a partir
8; des coordonnees de 2 points. Rq: on peut avoir un tableau de couple
9; de points.
10;
11; CATEGORY:petit truc qui peut etre utile (sans boucles, ca va de soit!)
12;
13; CALLING SEQUENCE:abc=linearequation(point1, point2)
14;
15; INPUTS: point1 et point2 dont deux point de(s) la droite(s) dont on
16; veut calculer l(es) equations(s).
17; deux possibilites sont possibles:
18;      1) point est un complexe ou un tableau de complexes, ou chaque
19;      element du complexe est les coordonnees du point
20;      2) points est un tableau de reels de dimensions 2
21;      ,nbre_de_droite. ou pour chaque ligne du tableau on a les
22;      coordonnees du point.
23;
24; KEYWORD PARAMETERS:
25;
26; OUTPUTS:abc c''est un tableau de dimensions 3, nbre_de_droite, ou
27; pour chaque ligne du tableau on obtient les 3 parametres a, b, c de
28; l'equation de la droite ax+by+c=0
29;
30; COMMON BLOCKS:
31;
32; SIDE EFFECTS:
33;
34; RESTRICTIONS:
35;
36; EXAMPLE:
37;    IDL> abc=linearequation(complex(1,2),[3,4])
38;    IDL> print, abc[0]*1+abc[1]*2+abc[2]
39;          0.00000
40;
41; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
42;                       10 juin 2000
43;-
44;------------------------------------------------------------
45;------------------------------------------------------------
46;------------------------------------------------------------
47FUNCTION linearequation, point1, point2
48;
49  compile_opt idl2, strictarrsubs
50;
51
52   if size(point1, /type) EQ 6 OR size(point1, /type) EQ 9 then begin
53      x1 = float(point1)
54      y1 = imaginary(point1)
55   ENDIF ELSE BEGIN
56      x1 = float(reform(point1[0, *]))
57      y1 = float(reform(point1[1, *]))
58   ENDELSE
59
60   if size(point2, /type) EQ 6 OR size(point2, /type) EQ 9 then begin
61      x2 = float(point2)
62      y2 = imaginary(point2)
63   ENDIF ELSE BEGIN
64      x2 = float(reform(point2[0, *]))
65      y2 = float(reform(point2[1, *]))
66   ENDELSE
67
68   vertical = where(x1 EQ x2)
69   novertical = where(x1 NE x2)
70   abc = fltarr(3, n_elements(x1))
71
72   IF novertical[0] NE -1 then BEGIN
73; y=mx+p
74      nele = n_elements(novertical)
75      m = (y2[novertical]-y1[novertical])/(x2[novertical]-x1[novertical])
76      p = (x2[novertical]*y1[novertical]-y2[novertical]*x1[novertical])/(x2[novertical]-x1[novertical])
77      abc[*, novertical] = [reform(-m, 1, nele), replicate(1, 1, nele), reform(-p, 1, nele)]
78   ENDIF
79   IF vertical[0] NE -1 then BEGIN
80; x=ny+p
81      nele = n_elements(vertical)
82      n = (x2[vertical]-x1[vertical])/(y2[vertical]-y1[vertical])
83      p = (y2[vertical]*x1[vertical]-x2[vertical]*y1[vertical])/(y2[vertical]-y1[vertical])
84      abc[*, vertical] = [replicate(1, 1, nele), reform(-n, 1, nele), reform(-p, 1, nele)]
85   ENDIF
86
87   return, abc
88end
Note: See TracBrowser for help on using the repository browser.