# 山体阴影工具的工作原理

## 山体阴影计算

### 山体阴影算法

``(1) Hillshade = 255.0 * ((cos(Zenith_rad) * cos(Slope_rad)) + (sin(Zenith_rad) * sin(Slope_rad) * cos(Azimuth_rad - Aspect_rad)))``

### 计算入射角度

``(2) Zenith_deg = 90.0 - Altitude``

``(3) Zenith_rad = Zenith_deg * pi / 180.0``

### 计算入射方向

``(4) Azimuth_math = 360.0 - Azimuth + 90.0``

``(5) Azimuth_math = Azimuth_math - 360.0``

``(6) Azimuth_rad = Azimuth_math * pi / 180.0``

### 计算坡度和坡向

``(7) [dz/dx] = ((c + 2f + i) - (a + 2d + g)) / (8 * cellsize)``

``(8) [dz/dy] = ((g + 2h + i) - (a + 2b + c)) / (8 * cellsize)``

``(9) Slope_rad = ATAN (z_factor * √ ([dz/dx]2 + [dz/dy]2))``

``(10) If [dz/dx] is non-zero: Aspect_rad = atan2 ([dz/dy], -[dz/dx]) if Aspect_rad < 0 then Aspect_rad = 2 * pi + Aspect_rad If [dz/dx] is zero: if [dz/dy] > 0 then Aspect_rad = pi / 2 else if [dz/dy] < 0 then Aspect_rad = 2 * pi - pi / 2 else Aspect_rad = Aspect_rad``

## 山体阴影计算示例

• 入射角度

根据等式 2 进行天顶角计算如下：

``(2) Zenith_deg = 90.0 - Altitude = 90.0 - 45.0 = 45.0``

根据等式 3 转换为弧度如下：

``(3) Zenith_rad = Zenith_deg * pi / 180.0 = 45.0 * 3.1415926536 / 180.0 = 0.7853981634``

• 入射方向

根据等式 4 将方位角从地理角度转换为数学角度的计算如下：

``(4) Azimuth_math = 360.0 - Azimuth + 90.0 = 360.0 - 315.0 + 90.0 = 135.0``

根据等式 6 将方位角转换为弧度如下：

``(6) Azimuth_rad = Azimuth_math * pi / 180.0 = 135.0 * 3.1415926536 / 180 = 2.3561944902``

• 坡度和坡向

中心像元 e 在 x 方向上的变化率的计算结果如下：

``(7) [dz/dx] = ((c + 2f + i) - (a + 2d + g)) / (8 * cellsize) = ((2483 + 4966 + 2477) - (2450 + 4904 + 2447)) / (8 * 5) = (9926 - 9801) / 40 = 3.125``

中心像元 e 在 y 方向上的变化率的计算结果如下：

``(8) [dz/dy] = ((g + 2h + i) - (a + 2b + c)) / (8 * cellsize) = (2447 + 4910 + 2477) - (2450 + 4922 + 2483) / (8 * 5) = (9834 - 9855) / 40 = -0.525``

坡度角的计算结果如下：

``(9) Slope_rad = ATAN ( z_factor * √ ([dz/dx]2 + [dz/dy]2)) = atan(1 * sqrt((3.125 * 3.125) + (-0.525 * -0.525))) = atan(1 * sqrt(10.04125 + 0.275625)) = atan(1 * 3.1687931457) = 1.2651101670``

根据规则 10 计算 Aspect_rad 角（因为本例中 dz/dx 为非零值）所得出的结果如下：

``Aspect_rad = atan2 ([dz/dy], -[dz/dx]) = atan2(-0.525, -3.125) = -2.9751469600``

由于计算得出的值小于零，因此使用此规则部分：

``Aspect_rad = 2 * pi + Aspect_rad = 2 * 3.1415926536 + -2.9751469600 = 3.3080383471``

• 山体阴影

山体阴影最终计算如下：

``Hillshade = 255.0 * ((cos(Zenith_rad) * cos(Slope_rad)) + (sin(Zenith_rad) * sin(Slope_rad) * cos(Azimuth_rad - Aspect_rad))) = 255.0 * ((cos(0.7857142857) * cos(1.26511)) + (sin(0.7857142857) * sin(1.26511) * cos(2.3571428571 - 3.310567))) = 153.82``

## 参考资料

Burrough, P. A., and R. A. McDonell. 1998. Principles of Geographical Information Systems. New York: Oxford University Press.