|||
功能是计算线段与坐标轴的夹角,与中学时学的一样,计算线段AB返回结果是那个α,单位为弧度。
;根据两点坐标返回线段与坐标轴的夹角(弧度)
;Point1到point2线段(线段AB)
;
Function Cal2PointsAngle ,point1,point2
dx = point2[0]- point1[0]
dy = point2[1]- point1[1]
IF dx EQ 0 THEN BEGIN ; x轴
IF dy GT 0 THEN result = !PI/2 ELSE $
result = 3*!PI/2
ENDIF ELSE BEGIN
IF dy EQ 0 THEN BEGIN ;x轴
IF dx GT 0 THEN result = 0 ELSE $
result = !PI
ENDIF ElSE BEGIN
result = ATAN(dy/dx)
IF result GT 0 THEN IF dx LT 0 THEN result = result +!Pi
IF result LT 0 THEN IF dx LT 0 THEN result = result +!Pi ELSE $
result = result + 2*!PI
ENDELSE
END
return,result MOD (2*!PI)
END
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-22 09:31
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社