本文整理汇总了C#中MissionPlanner.Utilities.utmpos.GetDistance方法的典型用法代码示例。如果您正苦于以下问题:C# utmpos.GetDistance方法的具体用法?C# utmpos.GetDistance怎么用?C# utmpos.GetDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MissionPlanner.Utilities.utmpos
的用法示例。
在下文中一共展示了utmpos.GetDistance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: findClosestLine
static linelatlng findClosestLine(utmpos start, List<linelatlng> list, double minDistance, double angle)
{
// By now, just add 5.000 km to our lines so they are long enough to allow intersection
double METERS_TO_EXTEND = 5000000;
double perperndicularOrientation = AddAngle(angle, 90);
// Calculation of a perpendicular line to the grid lines containing the "start" point
/*
* --------------------------------------|------------------------------------------
* --------------------------------------|------------------------------------------
* -------------------------------------start---------------------------------------
* --------------------------------------|------------------------------------------
* --------------------------------------|------------------------------------------
* --------------------------------------|------------------------------------------
* --------------------------------------|------------------------------------------
* --------------------------------------|------------------------------------------
*/
utmpos start_perpendicular_line = newpos(start, perperndicularOrientation, -METERS_TO_EXTEND);
utmpos stop_perpendicular_line = newpos(start, perperndicularOrientation, METERS_TO_EXTEND);
// Store one intersection point per grid line
Dictionary<utmpos, linelatlng> intersectedPoints = new Dictionary<utmpos, linelatlng>();
// lets order distances from every intersected point per line with the "start" point
Dictionary<double, utmpos> ordered_min_to_max = new Dictionary<double, utmpos>();
foreach (linelatlng line in list)
{
// Extend line at both ends so it intersecs for sure with our perpendicular line
utmpos extended_line_start = newpos(line.p1, angle, -METERS_TO_EXTEND);
utmpos extended_line_stop = newpos(line.p2, angle, METERS_TO_EXTEND);
// Calculate intersection point
utmpos p = FindLineIntersection(extended_line_start, extended_line_stop, start_perpendicular_line, stop_perpendicular_line);
// Store it
intersectedPoints[p] = line;
// Calculate distances between interesected point and "start" (i.e. line and start)
double distance_p = start.GetDistance(p);
if (!ordered_min_to_max.ContainsKey(distance_p))
ordered_min_to_max.Add(distance_p, p);
}
// Acquire keys and sort them.
List<double> ordered_keys = ordered_min_to_max.Keys.ToList();
ordered_keys.Sort();
// Lets select a line that is the closest to "start" point but "mindistance" away at least.
// If we have only one line, return that line whatever the minDistance says
double key = double.MaxValue;
int i = 0;
while (key == double.MaxValue && i < ordered_keys.Count)
{
if (ordered_keys[i] >= minDistance)
key = ordered_keys[i];
i++;
}
// If no line is selected (because all of them are closer than minDistance, then get the farest one
if (key == double.MaxValue)
key = ordered_keys[ordered_keys.Count-1];
// return line
return intersectedPoints[ordered_min_to_max[key]];
}
示例2: findClosestPoint
static utmpos findClosestPoint(utmpos start, List<utmpos> list)
{
utmpos answer = utmpos.Zero;
double currentbest = double.MaxValue;
foreach (utmpos pnt in list)
{
double dist1 = start.GetDistance(pnt);
if (dist1 < currentbest)
{
answer = pnt;
currentbest = dist1;
}
}
return answer;
}
示例3: CreateGrid
//.........这里部分代码省略.........
// store lines that dont have any intersections
List<linelatlng> remove = new List<linelatlng>();
int gridno = grid.Count;
// cycle through our grid
for (int a = 0; a < gridno; a++)
{
double closestdistance = double.MaxValue;
double farestdistance = double.MinValue;
utmpos closestpoint = utmpos.Zero;
utmpos farestpoint = utmpos.Zero;
// somewhere to store our intersections
List<utmpos> matchs = new List<utmpos>();
int b = -1;
int crosses = 0;
utmpos newutmpos = utmpos.Zero;
foreach (utmpos pnt in utmpositions)
{
b++;
if (b == 0)
{
continue;
}
newutmpos = FindLineIntersection(utmpositions[b - 1], utmpositions[b], grid[a].p1, grid[a].p2);
if (!newutmpos.IsZero)
{
crosses++;
matchs.Add(newutmpos);
if (closestdistance > grid[a].p1.GetDistance(newutmpos))
{
closestpoint.y = newutmpos.y;
closestpoint.x = newutmpos.x;
closestpoint.zone = newutmpos.zone;
closestdistance = grid[a].p1.GetDistance(newutmpos);
}
if (farestdistance < grid[a].p1.GetDistance(newutmpos))
{
farestpoint.y = newutmpos.y;
farestpoint.x = newutmpos.x;
farestpoint.zone = newutmpos.zone;
farestdistance = grid[a].p1.GetDistance(newutmpos);
}
}
}
if (crosses == 0) // outside our polygon
{
if (!PointInPolygon(grid[a].p1, utmpositions) && !PointInPolygon(grid[a].p2, utmpositions))
remove.Add(grid[a]);
}
else if (crosses == 1) // bad - shouldnt happen
{
}
else if (crosses == 2) // simple start and finish
{
linelatlng line = grid[a];
line.p1 = closestpoint;
line.p2 = farestpoint;
grid[a] = line;
}
else // multiple intersections
示例4: findClosestLine
static linelatlng findClosestLine(utmpos start, List<linelatlng> list)
{
linelatlng answer = list[0];
double shortest = double.MaxValue;
foreach (linelatlng line in list)
{
double ans1 = start.GetDistance(line.p1);
double ans2 = start.GetDistance(line.p2);
utmpos shorterpnt = ans1 < ans2 ? line.p1 : line.p2;
if (shortest > start.GetDistance(shorterpnt))
{
answer = line;
shortest = start.GetDistance(shorterpnt);
}
}
return answer;
}
示例5: cos_aob
public static double cos_aob (utmpos a, utmpos o, utmpos b)
{
double A = a.GetDistance(o), B = b.GetDistance(o), C = a.GetDistance(b);
return (- C * C + A * A + B * B) / (2 * A * B);
}