[2] | 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 | ;------------------------------------------------------------ |
---|
| 47 | FUNCTION linearequation, point1, point2 |
---|
| 48 | |
---|
| 49 | if size(point1, /type) EQ 6 OR size(point1, /type) EQ 9 then begin |
---|
| 50 | x1 = float(point1) |
---|
| 51 | y1 = imaginary(point1) |
---|
| 52 | ENDIF ELSE BEGIN |
---|
| 53 | x1 = float(reform(point1[0, *])) |
---|
| 54 | y1 = float(reform(point1[1, *])) |
---|
| 55 | ENDELSE |
---|
| 56 | |
---|
| 57 | if size(point2, /type) EQ 6 OR size(point2, /type) EQ 9 then begin |
---|
| 58 | x2 = float(point2) |
---|
| 59 | y2 = imaginary(point2) |
---|
| 60 | ENDIF ELSE BEGIN |
---|
| 61 | x2 = float(reform(point2[0, *])) |
---|
| 62 | y2 = float(reform(point2[1, *])) |
---|
| 63 | ENDELSE |
---|
| 64 | |
---|
| 65 | vertical = where(x1 EQ x2) |
---|
| 66 | novertical = where(x1 NE x2) |
---|
| 67 | abc = fltarr(3, n_elements(x1)) |
---|
| 68 | |
---|
| 69 | IF novertical[0] NE -1 then BEGIN |
---|
| 70 | ; y=mx+p |
---|
| 71 | nele = n_elements(novertical) |
---|
| 72 | m = (y2[novertical]-y1[novertical])/(x2[novertical]-x1[novertical]) |
---|
| 73 | p = (x2[novertical]*y1[novertical]-y2[novertical]*x1[novertical])/(x2[novertical]-x1[novertical]) |
---|
| 74 | abc[*, novertical] = [reform(-m, 1, nele), replicate(1, 1, nele), reform(-p, 1, nele)] |
---|
| 75 | ENDIF |
---|
| 76 | IF vertical[0] NE -1 then BEGIN |
---|
| 77 | ; x=ny+p |
---|
| 78 | nele = n_elements(vertical) |
---|
| 79 | n = (x2[vertical]-x1[vertical])/(y2[vertical]-y1[vertical]) |
---|
| 80 | p = (y2[vertical]*x1[vertical]-x2[vertical]*y1[vertical])/(y2[vertical]-y1[vertical]) |
---|
| 81 | abc[*, vertical] = [replicate(1, 1, nele), reform(-n, 1, nele), reform(-p, 1, nele)] |
---|
| 82 | ENDIF |
---|
| 83 | |
---|
| 84 | return, abc |
---|
| 85 | end |
---|