/// <summary> /// returns tiles forming a line between origin and target tile, optionally including the origin tile itself /// </summary> /// TODO: explain nudge /// ![yellow = origin , blue = target, yellow/blue = line, when includeOrigin = true the origin belongs is part of the line](GetTiles_Line.png) public static List <Vector3Int> Line(Vector3Int origin, Vector3Int target, bool includeOrigin, float horizontalNudgeFromOriginCenter = NudgePositive) { if (origin == target) { throw new System.ArgumentException("origin corner and target corner are the same - can't create a Path"); } List <Vector3Int> lineCells = new List <Vector3Int>(); if (includeOrigin) { lineCells.Add(origin); } int dist = GetDistance.BetweenTiles(origin, target); for (int i = 1; i <= dist; i++) { Vector3 lerped = HexUtility.LerpCubeCoordinates(origin, target, horizontalNudgeFromOriginCenter, (1f / dist) * i); Vector3Int cell = HexUtility.RoundCubeCoordinate(lerped); lineCells.Add(cell); } return(lineCells); }
private static float ComputeHausdorffDistance <T>(T[] orig, T[] converted, GetDistance <T> getDistance) { Assert.AreEqual(orig.Length, converted.Length); // Compute the Hausdorff distance to determine if two meshes have the same vertices as // we can't rely on the vertex order matching. float maxDistance = 0; for (int j = 0; j < orig.Length; j++) { float minDistance = float.PositiveInfinity; var pos = orig[j]; for (int k = 0; k < orig.Length; k++) { // find closest vertex in convertedMeshes var convertedPos = converted[k]; var distance = getDistance(pos, convertedPos); if (distance < minDistance) { minDistance = distance; } } if (minDistance > maxDistance) { maxDistance = minDistance; } } return(maxDistance); }
void Start() { distanceTool = GetComponent <GetDistance>(); StartCoroutine(DoSendDistance(distanceTool.updateRate)); StartCoroutine(DelayOpenCollider()); }
async public Task <string> OnButtonSearched(CustomMap customMap, string searchText) { IsSearching = true; var result = await AppData.Spaces.GeocodeAddress(searchText); System.Diagnostics.Debug.WriteLine(result); if (result == "") { IsSearching = false; return("Not found"); } string[] index = result.Split('&'); var address = index[0]; var lat = Convert.ToDouble(index[1]); var lon = Convert.ToDouble(index[2]); var name = index[3]; AppData.Spaces.tmpSpaceCollection.Clear(); foreach (var item in AppData.Spaces.PostsCollection) { double value = GetDistance.DistanceFromMeToLocation(lat, lon, item.GeoLatitude, item.GeoLongitude); if (value <= 10) //within the 10 mi radius { tmpSpaceData tmp = new tmpSpaceData(item, lat, lon); AppData.Spaces.tmpSpaceCollection.Add(tmp); } } if (AppData.Spaces.tmpSpaceCollection.Count == 0) { IsSearching = false; return("No space nearby"); } AppData.Spaces.IsListDataUpdated = true; IsFirstime = true; IsSearching = false; IsBusy = true; await LoadPin(customMap); await Task.Delay(1000); var position = new Position(lat, lon); customMap.Pins.Add(new Pin { Label = "Search Location", Position = position, Address = address }); customMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1.2))); IsBusy = false; return("Found"); }
/// <summary> /// returns the shortest path of corners from the origin to the target corner - optionally including the origin /// </summary> /// ![green = origin , purple = target, blue/purple = result - origin can optionally be included](GetCorners_PathAlongGrid.png) public static List <Vector3Int> PathAlongGrid(Vector3Int originCorner, Vector3Int targetCorner, bool includeOrigin, float horizontalNudgeFromOriginCenter = NudgePositive) { if (originCorner == targetCorner) { throw new System.ArgumentException("origin corner and target corner are the same - can't create a Path"); } List <Vector3Int> corners = new List <Vector3Int>(); if (includeOrigin) { corners.Add(originCorner); } Vector3Int previousCorner = originCorner; Vector3 cartesianOrigin = HexConverter.CornerCoordToCartesianCoord(originCorner) + new Vector3(horizontalNudgeFromOriginCenter, 0, 0); Vector3 cartesianTarget = HexConverter.CornerCoordToCartesianCoord(targetCorner); int dist = GetDistance.BetweenCorners(originCorner, targetCorner); for (int i = 1; i <= dist; i++) { Vector3 lerped = Vector3.Lerp(cartesianOrigin, cartesianTarget, (1f / dist) * i); Vector3Int tileCoord = HexConverter.CartesianCoordToTileCoord(lerped); List <Vector3Int> cornerCoords = HexGrid.GetCorners.OfTile(tileCoord); cornerCoords.RemoveAll(x => HexGrid.GetDistance.BetweenCorners(previousCorner, x) != 1); Vector3Int closestCorner = new Vector3Int(); float minDistanceSoFar = float.MaxValue; for (int j = 0; j < cornerCoords.Count; j++) { Vector3 worldPos = HexConverter.CornerCoordToCartesianCoord(cornerCoords[j]); float distance = Vector3.Distance(worldPos, lerped); if (distance < minDistanceSoFar) { closestCorner = cornerCoords[j]; minDistanceSoFar = distance; } } corners.Add(closestCorner); previousCorner = closestCorner; } return(corners); }
public static Vector2[] Run(Vector2 location, Vector2[] targets, GetDistance getDistance) { Region StartRegion = Game1.Grid.getRegion(location); PriorityQueue sortedRegionList = new PriorityQueue(); RouteTree routeTree = new RouteTree(); routeTree.AddFirst(StartRegion); List <Region> targetRegions = new List <Region>(); foreach (Vector2 target in targets) { targetRegions.Add(Game1.Grid.getRegion(target)); } Region currentRegion = StartRegion; while (!targetRegions.Contains(currentRegion)) { for (int i = 0; i < 8; i++) { Region region = currentRegion.Neighbours[i]; if (region.ContainsObstacle() == false) { if (routeTree.Contains(currentRegion.Neighbours[i]) == false) { var distance = getDistance(StartRegion.Middle, region.Middle, targetRegions[0].Middle); sortedRegionList.Add(distance, region); } routeTree.Add(region, currentRegion, currentRegion.edges[i].Length, currentRegion.edges[i]); } } currentRegion = sortedRegionList.Pop(); if (currentRegion == null) { return(null); } } return(routeTree.GetPath(currentRegion)); }
public tmpSpaceData(SpaceData item, double lat, double lon) { _id = item.ID; _title = item.Title; _streetaddress = item.StreetAddress; _imageurl = item.ImageURL; _geolatitude = item.GeoLatitude; _geolongitude = item.GeoLongitude; double distance = GetDistance.DistanceFromMeToLocation(lat, lon, item.GeoLatitude, item.GeoLongitude); _distance = distance; if (string.IsNullOrEmpty(_streetaddress) || string.IsNullOrWhiteSpace(_streetaddress)) { GetReverseGeoAddress(_geolatitude, _geolongitude); } }
public void SetData(List <T> datas, GetDistance distance) { //随机分配到各个中心 for (int i = 0; i < datas.Count; i++) { Data.Add(new Subset(i % _particle, datas[i])); } if (_getlength == null) { _getlength = distance; } //第一次分配中心点 for (int i = 0; i < _particle; i++) { _cluster[i].Data = Data[Data.Count / (i + 1) - 1].Data; } SetCenter(); }
/// <summary> /// returns the shared corner of the input tile coordinates /// </summary> /// TODO Add image public static Vector3Int BetweenNeighbouringTileCoordinates(Vector3Int a, Vector3Int b, Vector3Int c) { if (GetDistance.BetweenTiles(a, b) != 1) { throw new System.ArgumentException("Tiles a and b don't have a distance of 1, therefore and not neighbours and share no Edge"); } if (GetDistance.BetweenTiles(a, c) != 1) { throw new System.ArgumentException("Tiles a and c don't have a distance of 1, therefore and not neighbours and share no Edge"); } if (GetDistance.BetweenTiles(b, c) != 1) { throw new System.ArgumentException("Tiles b and c don't have a distance of 1, therefore and not neighbours and share no Edge"); } Vector3Int cornerCoordinate = a + b + c; return(cornerCoordinate); }
public ActionResult VisAvganger(Strekning valgtStrekning) { var strekning = new Strekning(); strekning.SettStrekning(valgtStrekning); //Henter Pris fra API strekning.Pris = GetDistance.GetDistanceFromApi(valgtStrekning.FraStasjon, valgtStrekning.TilStasjon); //Setter pris mtp. antall passasjerer og forskjellig pris på ulike billett typer. strekning.Pris = strekning.SettPris(); // Lagrer temporary data i en Session Cookie slik at vi kan bruke dataen/infoen ved redirection til Avganger TempData["Strekning"] = JsonConvert.SerializeObject(strekning); if (ModelState.IsValid) { return(RedirectToAction("Avganger", strekning)); } return(RedirectToAction("Index")); }
private void SearchLocation_old() { try { string postCode = txtAddress.Text.Trim(); if (string.IsNullOrEmpty(postCode)) { //MessageBox.Show("Please enter a PostCode"); MessageBox.Show("Please enter a Address"); return; } //postCode = General.GetPostCodeMatch(postCode); var latlng = GetDistance.PostCodeToLongLat(postCode, "GB"); if (latlng != null) { GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(latlng.Value.Latitude, latlng.Value.Longitude); gMapControl1.Position = point; GMapOverlay polyOverlay = new GMapOverlay(gMapControl1, "overlayJob"); GMapMarkerCustom marker1 = new GMapMarkerCustom(new PointLatLng(Convert.ToDouble(latlng.Value.Latitude), Convert.ToDouble(latlng.Value.Longitude)), Resources.Resource1.pushpin_PassengerOnBoard); marker1.ToolTipMode = MarkerTooltipMode.Always; marker1.Tag = new PointLatLng(latlng.Value.Latitude, latlng.Value.Longitude); polyOverlay.Markers.Add(marker1); gMapControl1.Overlays.Clear(); gMapControl1.Overlays.Add(polyOverlay); gMapControl1.Zoom = 16; } } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } }
/// <summary> /// returns all tiles of a ring around center in no defined order /// </summary> /// ![yellow = origin , green = ring tiles](GetTiles_Ring.png) public static List <Vector3Int> Ring(Vector3Int center, int radius, int ringThicknessInwards) { if (radius < 1) { throw new System.ArgumentException("radius needs to be larger than 0"); } if (ringThicknessInwards < 1) { throw new System.ArgumentException("ring thickness must be larger than 0"); } List <Vector3Int> ring = new List <Vector3Int>(); List <Vector3Int> allInManhattanrange = Disc(center, radius, true); foreach (var v in allInManhattanrange) { if (GetDistance.BetweenTiles(center, v) > radius - ringThicknessInwards) { ring.Add(v); } } return(ring); }
/// <summary> Returns distance between 2 satellites</summary> /// <param name="id_A">Satellite Source id</param> /// <param name="id_B">Satellite Target id</param> public static double GetCommsDistance(Guid id_A, Guid id_B) { return(RT_API != null && GetDistance != null ? (double)GetDistance.Invoke(null, new Object[] { id_A, id_B }) : 0.0); }
public static Vector2[] Run(Vector2 location, Vector2 target, GetDistance getDistance) { return(Run(location, new Vector2[] { target }, getDistance)); }
private void SearchLocation() { try { string postCode = txtAddress.Text.Trim(); string radius = txtRadius.Text.Trim(); double doubleRadius; if (string.IsNullOrEmpty(postCode)) { //MessageBox.Show("Please enter a PostCode"); ENUtils.ShowMessage("Please enter a Address"); return; } else if (string.IsNullOrEmpty(radius)) { ENUtils.ShowMessage("Please enter Radius."); return; } else if (!double.TryParse(radius, out doubleRadius)) { ENUtils.ShowMessage("Radius must be in number."); return; } stp_getCoordinatesByAddressResult baseCoordinates = null; if (chkWithinRadius.Checked) { baseCoordinates = new TaxiDataContext().stp_getCoordinatesByAddress(AppVars.objPolicyConfiguration.BaseAddress.ToStr(), General.GetPostCodeMatch(AppVars.objPolicyConfiguration.BaseAddress.ToStr())).FirstOrDefault(); } if (baseCoordinates != null && baseCoordinates.Latitude.HasValue && baseCoordinates.Longtiude.HasValue) { SearchPlaces = GetDistance.SearchPlaces(postCode, new GetDistance.Coords() { Latitude = baseCoordinates.Latitude.Value, Longitude = baseCoordinates.Longtiude.Value }, doubleRadius); if (SearchPlaces != null && SearchPlaces.Status == "OK") { if (SearchPlaces.Result.Count > 0) { var result = SearchPlaces.Result[0]; var latLng = new PointLatLng(Convert.ToDouble(result.Geometry.Location.Lat), Convert.ToDouble(result.Geometry.Location.Lng)); DrawPoint(latLng); dgvLocations.Visible = true; CreateListOfLocations(SearchPlaces); BringToFront(); dgvLocations.Focus(); } else { dgvLocations.Columns[0].HeaderText = string.Format("{0} Record(s) found", 0); dgvLocations.Rows.Clear(); if (gMapControl1.Overlays.Count > 0 && gMapControl1.Overlays[0].Markers.Count > 0) { gMapControl1.Overlays[0].Markers.Clear(); } } } else { dgvLocations.Visible = false; SearchLocation_old(); BringToFront(); txtAddress.Focus(); } } else { dgvLocations.Visible = false; SearchLocation_old(); BringToFront(); txtAddress.Focus(); } } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } }
// Use this for initialization void Start() { getDistance = this.transform.GetComponent <GetDistance>();//accessing class getDistance }