forked from ddrilling/AsbCloudServer
85 lines
3.4 KiB
C#
85 lines
3.4 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Repositories;
|
|
using AsbCloudApp.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Services.Trajectory
|
|
{
|
|
public class TrajectoryVisualizationPlanService : ITrajectoryVisualizationService<TrajectoryVisualizationPlanDto>
|
|
{
|
|
private readonly IPlannedTrajectoryRepository plannedRepository;
|
|
|
|
public TrajectoryVisualizationPlanService(IPlannedTrajectoryRepository plannedRepository)
|
|
{
|
|
this.plannedRepository = plannedRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Визуализация для плановой траектории по скважине
|
|
/// </summary>
|
|
/// <param name="idWell">ключ скважины</param>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
public async Task<IEnumerable<TrajectoryVisualizationPlanDto>> GetVisualizationAsync(int idWell, CancellationToken token)
|
|
{
|
|
var coords = await plannedRepository.GetTrajectoryAsync(idWell, token);
|
|
return GetTrajectoryVisualisation(coords);
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Формирует список координат для визуализации трактории 3D
|
|
/// </summary>
|
|
/// <param name="geoCoordinates"></param>
|
|
/// <returns></returns>
|
|
private IEnumerable<TrajectoryVisualizationPlanDto> GetTrajectoryVisualisation(IEnumerable<TrajectoryPlanDto> geoCoordinates)
|
|
{
|
|
var geoCoordinatesLength = geoCoordinates.Count();
|
|
if (geoCoordinatesLength < 2)
|
|
return new TrajectoryVisualizationPlanDto[0];
|
|
|
|
var cartesianCoordinates = new Location[geoCoordinatesLength];
|
|
cartesianCoordinates[0] = new();
|
|
|
|
var geoCoordinatesArray = geoCoordinates.OrderBy(c => c.WellboreDepth).ToArray();
|
|
for (var i = 1; i < geoCoordinatesLength; i++)
|
|
{
|
|
var intervalGeoParams = geoCoordinatesArray[i - 1];
|
|
var deltaWellLength = geoCoordinatesArray[i].WellboreDepth - intervalGeoParams.WellboreDepth;
|
|
var projectionLengthToXYSurface = deltaWellLength * Math.Sin(intervalGeoParams.ZenithAngle * Math.PI / 180);
|
|
|
|
var dDepth = deltaWellLength * Math.Cos(intervalGeoParams.ZenithAngle * Math.PI / 180);
|
|
var dNorth = projectionLengthToXYSurface * Math.Sin(intervalGeoParams.AzimuthGeo * Math.PI / 180);
|
|
var dEast = projectionLengthToXYSurface * Math.Cos(intervalGeoParams.AzimuthGeo * Math.PI / 180);
|
|
|
|
var preCoordinates = cartesianCoordinates[i - 1];
|
|
var coordinates = new Location(
|
|
preCoordinates.North + dNorth,
|
|
preCoordinates.East + dEast,
|
|
preCoordinates.Depth + dDepth,
|
|
geoCoordinatesArray[i].Radius,
|
|
geoCoordinatesArray[i].Comment
|
|
);
|
|
|
|
cartesianCoordinates[i] = coordinates;
|
|
}
|
|
|
|
return cartesianCoordinates.Select(location => new TrajectoryVisualizationPlanDto {
|
|
X = location.East,
|
|
Y = -location.Depth,
|
|
Z = -location.North,
|
|
Comment = location.Comment,
|
|
Radius = location.Radius
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
}
|