new ScanConverter method

This commit is contained in:
Tim Wundenberg
2021-08-17 18:14:03 +02:00
parent de049999ee
commit f3a0bac05e
5 changed files with 8 additions and 75 deletions

View File

@@ -48,9 +48,6 @@ namespace PointCloudWeb.Server.ScanConverter
//scan.RAY = (scan.RAY + 90) % 360;
return scan;
if (scan.RAX == 1) return scan;
return new ScanDataPoint();
}
}
}

View File

@@ -63,7 +63,6 @@ namespace PointCloudWeb.Server.Tests.Services
var expected = new Point(x, y, z);
var service = new ScanConverterService();
var point = ScanConverterService.Transform(scan);
Assert.Equal(expected, point);
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Utils;
namespace PointCloudWeb.Server.Services
{
@@ -38,7 +37,7 @@ namespace PointCloudWeb.Server.Services
private void InitSampleData()
{
EthTestData.CreateData(this);
//EthTestData.CreateData(this);
}
private void RaiseIfNotExists(Guid id)
@@ -61,7 +60,7 @@ namespace PointCloudWeb.Server.Services
public PointCloud AddPointCloud(Guid? id = null)
{
if (id != null && _pointClouds.Contains(id))
if (_pointClouds.Contains(id))
throw new ArgumentOutOfRangeException($"Add of existing id \"{id}\" not possible!");
var pc = new PointCloud(id ?? Guid.NewGuid(), $"Scan #{_pointClouds.Count + 1}");

View File

@@ -1,6 +1,5 @@
using System;
using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Utils;
namespace PointCloudWeb.Server.Services
{
@@ -8,73 +7,14 @@ namespace PointCloudWeb.Server.Services
{
public static Point Transform(ScanDataPoint scan)
{
// if (scan.RAX >= 90 || scan.RAY >= 90)
// return new Point(0, 0, 0);
var alpha = scan.RAX * Math.PI / 180;
var beta = scan.RAY * Math.PI / 180;
var degreeXa = (scan.RAX) % 360;
var degreeYa = scan.RAY;
var factorY = 1;
var factorZ = 1;
if (180 <= degreeXa && degreeXa <= 360)
{
factorY = -1;
factorZ = -1;
}
var degreeXb = 180 - 90 - degreeXa;
var degreeYb = 180 - 90 - degreeYa;
var radXa = degreeXa * Math.PI / 180;
var radXb = degreeXb * Math.PI / 180;
var radYa = degreeYa * Math.PI / 180;
var radYb = degreeYb * Math.PI / 180;
var sinXa = Math.Sin(radXa);
var sinXb = Math.Sin(radXb);
var sinYa = Math.Sin(radYa);
var sinYb = Math.Sin(radYb);
if (sinXa == 0)
{
sinXa = 1;
sinXb = 0;
}
if (sinYa == 0)
{
sinYa = 1;
sinYb = 0;
}
var z = Math.Sqrt(
Math.Pow(
Math.Pow(sinXb, 2) / Math.Pow(sinXa, 2)
+ Math.Pow(sinYb, 2) / Math.Pow(sinYa, 2)
+ 1
, -1)
* Math.Pow(scan.DistanceMM, 2)
var p = new Point(
y: (int)(scan.DistanceMM * Math.Sin(alpha)),
x: (int)(scan.DistanceMM * Math.Cos(beta) * Math.Cos(alpha)),
z: (int)(scan.DistanceMM * Math.Sin(beta) * Math.Cos(alpha))
);
var p = new Point
{
X = NumericUtils.Round(z * sinYb / sinYa),
Y = factorY * NumericUtils.Round(z * sinXb / sinXa),
Z = factorZ * NumericUtils.Round(z)
};
//return p;
//https://stackoverflow.com/questions/52781607/3d-point-from-two-angles-and-a-distance
var beta = radYa;
var alpha = radXa;
p = new Point
{
Y = (int)(scan.DistanceMM * Math.Sin(alpha)),
X = (int)(scan.DistanceMM * Math.Cos(beta) * Math.Cos(alpha)),
Z = (int)(scan.DistanceMM * Math.Sin(beta) * Math.Cos(alpha))
};
return p;
}
}

View File

@@ -38,12 +38,10 @@ namespace PointCloudWeb.Server.Utils
public static void CreateData(PointCloudService pointCloudService)
{
var pc = pointCloudService.AddPointCloud();
pc.Name = "Scan 1";
LoadPointCloudFromEthFile(pc, "ETH-Data/Hokuyo_0.csv");
pointCloudService.PointCloudCompleted(pc.Id);
pc = pointCloudService.AddPointCloud();
pc.Name = "Scan 2";
LoadPointCloudFromEthFile(pc, "ETH-Data/Hokuyo_1.csv");
pointCloudService.PointCloudCompleted(pc.Id);
}