Commit e5edfd3e authored by 谢旭's avatar 谢旭

完成距离显示

parent 003f813e
No preview for this file type
...@@ -23,6 +23,7 @@ namespace CefDemo.Controllers ...@@ -23,6 +23,7 @@ namespace CefDemo.Controllers
{ {
CalculateModel.SaveModel(model); CalculateModel.SaveModel(model);
CalculateModel.issetValue = true;
return "ok"; return "ok";
} }
// PUT api // PUT api
......
...@@ -13,10 +13,11 @@ namespace CefDemo.Extension ...@@ -13,10 +13,11 @@ namespace CefDemo.Extension
class CalculateModel class CalculateModel
{ {
static public List<Point> points = new List<Point>(); static public List<Point> points ;
static public Point Center ; static public Point Center ;
static public FenceModel Model; static public FenceModel Model;
static public bool issetValue =false;
public static bool IsSamePoint(Point p1,Point p2) public static bool IsSamePoint(Point p1,Point p2)
{ {
...@@ -43,7 +44,7 @@ namespace CefDemo.Extension ...@@ -43,7 +44,7 @@ namespace CefDemo.Extension
public static bool IsinPolyhedron(Point point ,List<Point> points,double Height) public static bool IsinPolyhedron(Point point ,List<Point> points,double Height)
{ {
int nCross = 0; int nCross = 0;
for (int i=0;i< points.Count();i++) for (int i=0;i< points.Count()-1;i++)
{ {
Point p1 = points.ElementAt(i); Point p1 = points.ElementAt(i);
Point p2 = points.ElementAt(i+1); Point p2 = points.ElementAt(i+1);
...@@ -93,7 +94,7 @@ namespace CefDemo.Extension ...@@ -93,7 +94,7 @@ namespace CefDemo.Extension
//计算点到面的距离 //计算点到面的距离
Vec3 B2point = new Vec3(firstPoint.X - point.X, firstPoint.Y - point.Y, firstPoint.Z - point.Z); Vec3 B2point = new Vec3(firstPoint.X - point.X, firstPoint.Y - point.Y, firstPoint.Z - point.Z);
double number_up = B2point.X * n.X + B2point.Y * n.Y + B2point.Z * n.Z; double number_up =Math.Abs( B2point.X * n.X + B2point.Y * n.Y + B2point.Z * n.Z);
double number_down = Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z); double number_down = Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z);
double d = number_up / number_down; double d = number_up / number_down;
numlist.Add(d); numlist.Add(d);
...@@ -123,21 +124,23 @@ namespace CefDemo.Extension ...@@ -123,21 +124,23 @@ namespace CefDemo.Extension
if (IsinPolyhedron(point, points, Height)) if (IsinPolyhedron(point, points, Height))
{ {
//在围栏内 //在围栏内
var dis = PointToPlane(points, point, Height, Buffer_dis); var dis = PointToPlane(points, point, Height, Buffer_dis);
if (dis >= Buffer_dis) if (dis >= Buffer_dis)
{ {
return "在缓冲区内"; return "在缓冲区内";
} }
else if( dis < Buffer_dis) else if( dis < Buffer_dis)
{ {
return $"距离电子围栏{dis}米"; var showdis = dis.ToString().Substring(0,5);
return $"距离电子围栏{showdis}米";
} }
} }
else else
{ {
//在围栏外 //在围栏外
var dis = PointToPlane(points, point, Height, Buffer_dis); var dis = PointToPlane(points, point, Height, Buffer_dis);
return $"超出电子围栏{dis}米"; var showdis = dis.ToShort();
return $"超出电子围栏{showdis}米";
} }
return ""; return "";
...@@ -179,12 +182,12 @@ namespace CefDemo.Extension ...@@ -179,12 +182,12 @@ namespace CefDemo.Extension
{ {
//缓冲区内 //缓冲区内
double _dis_R = Radius - _distance; double _dis_R = Radius - _distance;
return $"距离电子围栏{_dis_R}"; return $"距离电子围栏{_dis_R.ToShort()}";
} }
else if (_distance >= Radius) else if (_distance >= Radius)
{ {
//在球外 //在球外
return $"超出电子围栏{ _distance-Radius }"; return $"超出电子围栏{( _distance-Radius ).ToShort()}";
} }
return ""; return "";
} }
...@@ -220,11 +223,13 @@ namespace CefDemo.Extension ...@@ -220,11 +223,13 @@ namespace CefDemo.Extension
} }
else if (point.Z >= Height - Buffer_dis && point.Z < Height) else if (point.Z >= Height - Buffer_dis && point.Z < Height)
{ {
return $"超出缓冲区{point.Z - (Height - Buffer_dis)}米"; var showdis =( point.Z - (Height - Buffer_dis)).ToString().Substring(0,5);
return $"超出缓冲区{showdis}米";
} }
else if (point.Z>= Height) else if (point.Z>= Height)
{ {
return $"超出缓冲区{point.Z - (Height - Buffer_dis)}米,超出电子围栏{point.Z-Height}米"; var showdis = (point.Z - (Height - Buffer_dis)).ToShort();
return $"超出缓冲区{showdis}米,超出电子围栏{point.Z-Height}米";
} }
} }
...@@ -239,14 +244,14 @@ namespace CefDemo.Extension ...@@ -239,14 +244,14 @@ namespace CefDemo.Extension
if (_dis_height < 0) if (_dis_height < 0)
{ {
//高度没有超过 //高度没有超过
return $"距离电子围栏{_dis}米"; return $"距离电子围栏{_dis.ToShort()}米";
} }
else if (_dis_Height < 0 && _dis_height >= 0) else if (_dis_Height < 0 && _dis_height >= 0)
{ {
//缓冲区内 //缓冲区内
if (_dis >= Height - point.Z) if (_dis >= Height - point.Z)
{ {
return $"距离电子围栏{Height - point.Z}米"; return $"距离电子围栏{(Height - point.Z).ToShort()}米";
} }
else else
{ {
...@@ -256,10 +261,10 @@ namespace CefDemo.Extension ...@@ -256,10 +261,10 @@ namespace CefDemo.Extension
else if(_dis_Height >= 0) else if(_dis_Height >= 0)
{ {
return $"距离电子围栏{point.Z-Height }米"; return $"距离电子围栏{(point.Z-Height).ToShort() }米";
} }
return $"超出缓冲区{_dis}米"; return $"超出缓冲区{_dis.ToShort()}米";
} }
else if (_distance >= Radius) else if (_distance >= Radius)
...@@ -273,16 +278,16 @@ namespace CefDemo.Extension ...@@ -273,16 +278,16 @@ namespace CefDemo.Extension
{ {
if (_dis_Height >= _dis_R) if (_dis_Height >= _dis_R)
{ {
return $"超出电子围栏{_dis_R}米"; return $"超出电子围栏{_dis_R.ToShort()}米";
} }
else else
{ {
return $"超出电子围栏{_dis_Height}米"; return $"超出电子围栏{_dis_Height.ToShort()}米";
} }
} }
else else
{ {
return $"超出电子围栏{_dis_R}米"; return $"超出电子围栏{_dis_R.ToShort()}米";
} }
} }
...@@ -305,12 +310,14 @@ namespace CefDemo.Extension ...@@ -305,12 +310,14 @@ namespace CefDemo.Extension
{ {
if (model.FenceType == "polygon") if (model.FenceType == "polygon")
{ {
string pointsstr = model.points; string pointsstr = model.points;
var list = JsonConvert.DeserializeObject<List<DataModel>>(pointsstr); var list = JsonConvert.DeserializeObject<List<DataModel>>(pointsstr);
points = new List<Point>();
list.ForEach(p => { list.ForEach(p => {
points.Add(new Point(p.longitude, p.latitude, p.height)); points.Add(new Point(p.longitude, p.latitude, p.height));
}); });
points.Add(new Point(list.ElementAt(0).longitude, list.ElementAt(0).latitude, list.ElementAt(0).height));
} }
else if (model.FenceType == "sphere") else if (model.FenceType == "sphere")
{ {
...@@ -331,21 +338,42 @@ namespace CefDemo.Extension ...@@ -331,21 +338,42 @@ namespace CefDemo.Extension
public static string GetWarningInfo(Point point) public static string GetWarningInfo(Point point)
{ {
if (Model == null)
return "0.0";
if (Model.FenceType == "polygon") //多边体 if (Model.FenceType == "polygon") //多边体
{ {
return DistanceToPolyhedron(points, point, Convert.ToSingle(Model.Height), Convert.ToSingle(Model.Buffer_dis)); if (points == null && issetValue ==true)
{
return "0.0";
}
else
{
return DistanceToPolyhedron(points, point, Convert.ToSingle(Model.Height), Convert.ToSingle(Model.Buffer_dis));
}
} }
else if (Model.FenceType == "circle")//圆柱体 else if (Model.FenceType == "circle")//圆柱体
{ {
if (Center == null && issetValue == true)
return DistanceToCylinder(Center, Convert.ToSingle(Model.Radius), point, Convert.ToSingle(Model.Height), Convert.ToSingle(Model.Buffer_dis)); {
return "0.0";
}
else
{ return DistanceToCylinder(Center, Convert.ToSingle(Model.Radius), point, Convert.ToSingle(Model.Height), Convert.ToSingle(Model.Buffer_dis)); }
} }
else if (Model.FenceType == "sphere")//球体 else if (Model.FenceType == "sphere")//球体
{ {
if (Center == null && issetValue == true)
{
return "0.0";
}
else
{
return DistanceToSphere(point, Center, Convert.ToSingle(Model.Radius), Convert.ToSingle(Model.Buffer_dis)); return DistanceToSphere(point, Center, Convert.ToSingle(Model.Radius), Convert.ToSingle(Model.Buffer_dis));
}
} }
...@@ -353,5 +381,7 @@ namespace CefDemo.Extension ...@@ -353,5 +381,7 @@ namespace CefDemo.Extension
} }
} }
} }
...@@ -18,10 +18,17 @@ namespace CefDemo.Extension ...@@ -18,10 +18,17 @@ namespace CefDemo.Extension
{ {
reuslt = locationStr.ElementAt(i); reuslt = locationStr.ElementAt(i);
} }
} }
return reuslt; return reuslt;
} }
public static string ToShort(this double num)
{
return num.ToString().Substring(0,5);
}
} }
} }
...@@ -134,6 +134,11 @@ namespace CefDemo ...@@ -134,6 +134,11 @@ namespace CefDemo
string longitude = location.ElementAt(Convert.ToInt32(i++ % 16)).Value.ToString(); string longitude = location.ElementAt(Convert.ToInt32(i++ % 16)).Value.ToString();
string latitude = location.ElementAt(Convert.ToInt32(i++ % 16)).Key.ToString(); string latitude = location.ElementAt(Convert.ToInt32(i++ % 16)).Key.ToString();
string alitude = "50.32"; string alitude = "50.32";
string distance = CalculateModel.GetWarningInfo(new Point(Convert.ToSingle(longitude),
Convert.ToSingle(latitude),
Convert.ToSingle(alitude)
));
string sendMessage = "" + string sendMessage = "" +
"{\"deviceType\":\"RTK\"" + "{\"deviceType\":\"RTK\"" +
",\"SICVersion\":\"SIC_1.2\"" + ",\"SICVersion\":\"SIC_1.2\"" +
...@@ -150,10 +155,9 @@ namespace CefDemo ...@@ -150,10 +155,9 @@ namespace CefDemo
",\"deviceBrand\":\"SOUTH\"" + ",\"deviceBrand\":\"SOUTH\"" +
",\"receivetime\":\"20200630153620\"" + ",\"receivetime\":\"20200630153620\"" +
",\"longitude\":" + longitude + // ",\"longitude\":" + longitude + //
",\"WarningInfo\":" + CalculateModel.GetWarningInfo(new Point(Convert.ToSingle(longitude), ",\"WarningInfo\":" +"\""+ distance + "\"" +
Convert.ToSingle(latitude),
Convert.ToSingle(alitude) //",\"WarningInfo\":\"20200630153620\"" +
)) +
"}"; "}";
if (i==10000000) if (i==10000000)
{ {
...@@ -161,7 +165,7 @@ namespace CefDemo ...@@ -161,7 +165,7 @@ namespace CefDemo
} }
buffer = Encoding.UTF8.GetBytes(sendMessage); buffer = Encoding.UTF8.GetBytes(sendMessage);
await sendAsync(new ArraySegment<byte>(buffer, 0, buffer.Count()), 1, true, callCancelled); await sendAsync(new ArraySegment<byte>(buffer, 0, buffer.Count()), 1, true, callCancelled);
await Task.Delay(2000); await Task.Delay(5000);
} }
......
This diff is collapsed.
...@@ -391,3 +391,4 @@ C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\obj\x64\Debug\View\ConHardwa ...@@ -391,3 +391,4 @@ C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\obj\x64\Debug\View\ConHardwa
C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\bin\x64\Debug\System.Web.Cors.dll C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\bin\x64\Debug\System.Web.Cors.dll
C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\bin\x64\Debug\System.Web.Http.Cors.dll C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\bin\x64\Debug\System.Web.Http.Cors.dll
C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\bin\x64\Debug\System.Web.Http.Cors.xml C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\bin\x64\Debug\System.Web.Http.Cors.xml
C:\Users\captain.eugene\Desktop\CefDemo (2)\CefDemo\obj\x64\Debug\CefDemo.csprojAssemblyReference.cache
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment