AirTransmissionLibrary/docs/usage_examples.md
2025-01-03 12:03:50 +08:00

125 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用示例
本文档提供了在 C# 和 C++ 项目中使用大气传输计算库的示例。
## C# 调用示例
### 项目配置
1. 在 Visual Studio 中创建新的 .NET 项目
2. 将 AirTransmission.dll 复制到项目目录
3. 在项目中添加 DLL 引用:
- 右键点击项目 -> 添加 -> 引用
- 浏览 -> 选择 AirTransmission.dll
### 代码示例
```csharp
using AirTransmission;
// 创建天气条件
var weather = new WeatherCondition
{
Temperature = 20, // 温度(摄氏度)
Humidity = 0.65, // 相对湿度0-1
Pressure = 101.325, // 大气压力kPa
Visibility = 10000, // 能见度(米)
WeatherType = WeatherType.Clear // 天气类型
};
// 创建大气透过率计算器
var calculator = new AtmosphericTransmittanceCalculator();
// 计算激光透过率
double wavelength = 1.064; // 波长(微米)
double distance = 1000; // 传输距离(米)
double transmittance = calculator.CalculateTransmittance(wavelength, distance, weather);
Console.WriteLine($"激光透过率: {transmittance:P2}");
```
### 高级用法
```csharp
// 计算不同天气条件下的透过率
var weatherConditions = new[]
{
new WeatherCondition { WeatherType = WeatherType.Clear, Temperature = 20, Humidity = 0.65 },
new WeatherCondition { WeatherType = WeatherType.Cloudy, Temperature = 18, Humidity = 0.8 },
new WeatherCondition { WeatherType = WeatherType.Rain, Temperature = 15, Humidity = 0.95 }
};
var calculator = new AtmosphericTransmittanceCalculator();
double wavelength = 1.064; // 微米
double distance = 1000; // 米
foreach (var weather in weatherConditions)
{
var transmittance = calculator.CalculateTransmittance(wavelength, distance, weather);
Console.WriteLine($"天气: {weather.WeatherType}, 透过率: {transmittance:P2}");
}
// 计算大气湍流影响
var turbulence = calculator.CalculateAtmosphericTurbulence(wavelength, distance, weather);
Console.WriteLine($"大气湍流强度: {turbulence:E2}");
```
## C++ 调用示例
### 项目配置
1. 在 Visual Studio 中创建新的 C++ 项目
2. 将以下文件复制到项目目录:
- `AirTransmission.dll` - 动态链接库文件
- `include/AirTransmission.h` - 头文件
3. 在项目设置中添加 include 目录
4. 在代码中包含头文件并使用导出函数
### 代码示例
```cpp
#include "AirTransmission.h"
#include <iostream>
int main() {
// 设置参数
double wavelength = 1.064; // 波长(微米)
double distance = 1000.0; // 距离(米)
double temperature = 20.0; // 温度(摄氏度)
double relativeHumidity = 0.65; // 相对湿度0-1
double pressure = 101.325; // 大气压力kPa
double visibility = 10000.0; // 能见度(米)
int weatherType = WeatherType::Clear; // 天气类型(晴天)
// 计算透过率
double transmittance = CalculateTransmittance(
wavelength, distance, temperature, relativeHumidity,
pressure, visibility, weatherType
);
std::cout << "透过率: " << transmittance * 100.0 << "%" << std::endl;
// 计算湍流影响
double turbulence = CalculateAtmosphericTurbulence(
wavelength, distance, temperature, relativeHumidity,
pressure, visibility, weatherType
);
std::cout << "湍流强度: " << turbulence << std::endl;
return 0;
}
```
### 注意事项
1. 确保 AirTransmission.dll 在程序运行目录下
2. 头文件中已定义了所有必要的类型和函数
3. 使用 WeatherType 枚举来指定天气类型
4. 所有浮点数参数都使用 double 类型
5. 参数单位说明:
- 波长微米μm
- 距离m
- 温度:摄氏度(℃)
- 相对湿度0-1
- 压力千帕kPa
- 能见度m