How can we calculate bound from a point? - openstreetmap

I have a coordinate. How can we calculate the bounds that the point is centered in map?
Call that point O and its bound has size 5x5m
.
Do any of you have a solution? I don't have a solution yet.

Solution:
* Returns the Point resulting from moving a distance from an origin in the
* specified heading (expressed in degrees clockwise from north).
*
* #param from The Point from which to start.
* #param distance The distance to travel.
* #param heading The heading in degrees clockwise from north.
*/
public static Point computeOffset(Point from, double distance, double heading)
{
distance /= MathUtil.EARTH_RADIUS;
heading = MathUtil.convertToRadians(heading);
// http://williams.best.vwh.net/avform.htm#LL
double fromLat = MathUtil.convertToRadians(from.Lat);
double fromLng = MathUtil.convertToRadians(from.Lng);
double cosDistance = Math.Cos(distance);
double sinDistance = Math.Sin(distance);
double sinFromLat = Math.Sin(fromLat);
double cosFromLat = Math.Cos(fromLat);
double sinLat = cosDistance * sinFromLat + sinDistance * cosFromLat * Math.Cos(heading);
double dLng = Math.Atan2(sinDistance * cosFromLat * Math.Sin(heading), cosDistance - sinFromLat * sinLat);
return new Point(MathUtil.toDegreesFromRadians(Math.Asin(sinLat)), MathUtil.toDegreesFromRadians(fromLng + dLng));
}

Related

User is Inside or not Geofense Flutter

i am creating flutter attendance app where i want to check when user is marking attendance he/she is available in office area or not? if not show them how much distance they are away from radius.
i tried using this but not getting the appropriate result. i want to check 200m radius from lat long.
double geDistance(double lat1, double lon1, double lat2, double lon2) {
double theta = lon1 - lon2;
double dist = sin(toRadians(lat1)) * sin(toRadians(lat2)) +
cos(toRadians(lat1)) * cos(toRadians(lat2)) * cos(toRadians(theta));
dist = acos(dist);
dist = toDegrees(dist);
dist = dist * 60 * 1.1515;
dist = dist * 1000 * 1.609344;
///dist in meter
return dist;
}
double toRadians(double degree) {
return degree * pi / 180;
}
double toDegrees(double radian) {
return radian * 180 / pi;
}
i know geofense can resolve accurately this but i have no idea which method can help me to check user location is inside radius or not.

How to change the distance/radius from center that the objects are instantiated

How would it be possible to move the 8 instantiatedObjects "cubes" closer to the pillar.
public void instantiateInCircle()
{
for (int i = 0; i < amount; i++)
{
float radius = 8;
float angle = i * Mathf.PI * 2f / radius;
Vector3 newPos = transform.position + (new Vector3(Mathf.Cos(angle) * radius, spawnHeight, Mathf.Sin(angle) * radius ));
GameObject instantiatedObject = Instantiate(itemToSpawn, newPos, Quaternion.Euler(0, 0, 0));
instantiatedObject.transform.LookAt(spawnAroundThis.transform);
instantiatedObject.transform.parent = spawnAroundThis.transform;
instantiatedObject.transform.localScale = new Vector3(scale, scale, scale);
//this seems to work-ish , not sure if its good math but hey :)
//Thanks BugFinder!
instantiatedObject.transform.position = instantiatedObject.transform.position += instantiatedObject.transform.forward * distance;
}
}
Ideally these could be moved closer to the pillar
Due to the fact your code already points the object towards where you are trying to get closer, you need only move the object forward until its at the correct distance.
Decreasing the value of the radius variable should spawn them closer to the pillar.
Since you are offsetting the cube position from the pillar position by the cosine and sine components of the radius, it will place them correctly spaced around the pillar.
Also, I believe
float angle = i * Mathf.PI * 2f / radius;
Should really be
float angle = i * Mathf.PI * 2f / amount;
The radius should not affect the angle the object is spawned, but the number of objects should.

How to get data that is all within radius of somewhere, and within the radius I'm looking for?

I am using postgres and postgis.
I have Posts which have a geometry, with an attribute visible_within_m which is how many meters from that point the Post should be shown in results.
I can find Posts within some random radius of some random points by doing ST_DWithin(geometry, ST_SetSRID(ST_Point(a, b), 4326), 10000)
However, I want to know how many Posts are visible with a radius of some random point.
How can I look up how many Posts are visible within a radius of some arbitrary point?
Is there a better way to do this?
You can calculate the distance between each point and the center of your circle. If the distance is grater than the radius then it is outside otherwise it's inside.
const EARTH_RADIUS = 6371000;
const toRad = function(num){return num*Math.PI/180};
var calculateDistance =
function(lat1, lon1, lat2, lon2){
var dLat = toRad(lat2 - lat1);
var dLon = toRad(lon2 - lon1);
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(toRad(lat1)) *
Math.cos(toRad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
var distance = EARTH_RADIUS * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return distance;
}
Instead of using a constant value for the distance, use the value stored in visible_within_m
SELECT * FROM mytable
WHERE ST_DWithin(geometry, ST_SetSRID(ST_Point(a, b), 4326), visible_within_m);
On a side note, st_dwithin with geometries uses the distance unit of the projection, so for 4326 it is a (meaningless) distance in degrees, not in meters.

What is the size limit of the gameobjects?

I am building an AR application with unity and Mapbox. I have a point to represents a building. I can geolocate the point through Mapbox. I want to see this object everywhere. So, I change the size of objects according to distance.
Firstly, the code is working. But, I could not see the point really far away, 5 km away.
// Update is called once per frame
void Update()
{
// Get user location
// Latitude
x = getLocation.x1.ToString();
user_lat = Convert.ToDouble(x);
user_lat_rad = Math.PI * user_lat / 180.0; // Radian
// Longitude
y = getLocation.y1.ToString();
user_lon = Convert.ToDouble(y);
user_lon_rad = Math.PI * user_lon / 180.0; // Radian
// Change POIs sizes
distances = distance(user_lat_rad, user_lon_rad);
double s = 0.3; // size of the poi
double d = 50f; // specific distance to point (reference distance)
double size = (distances * s) / d;
float size2 = Convert.ToSingle(size);
temp = transform.localScale;
temp.x = size2;
temp.y = size2;
temp.z = size2;
transform.localScale = temp;
}
public double distance(double lat2, double lon2)
{
// Haversine Formula
// Lat2,Lon2 = User Location
// Lat1,Lon1 = POI Location
double dist1 = Sqrt((Pow(Sin((lat2 - lat1) / 2), 2)) + Cos(lat2) * Cos(lat2) * (Pow(Sin((lon2 - lon1) / 2), 2)));
double distance = 2 * r * Asin(dist1);
return distance;
}
Why I couldn't see the point far away even though object size is change? Is there any limitation for this?
As said in the comments the issue most probably is a too small value for the Camera's farClipPlane.
The furthest point relative to the camera that drawing will occur.
Any object/triangle that is further away from the Camera will not be rendered.
In the Inspector it is configured on the Camera component &rightarrow; Clipping Planes &rightarrow; Far
or using code
cameraReference.farClipPlane = XYZ;

iPhone: calculate distance while walking using GPS

I want to calculate the distance that users cover while walking using GPS. For example a user taps the start button and starts to walk or run than when he done he taps stop. What will be the minimum distance user has to travel to get the different lat long?
How can we do it in IPhone, asume we take Lat, long after every 0.3 sec than in the last we have a list of points?
You could do this by calculating the distance between 2 points (latitude, longitude):
(I haven't tested it):
-(double)distanceBetweenCoordinate:(CLLocationCoordinate2D)c1 andCoordinate:(CLLocationCoordinate2D)c2 {
double long1 = degreesToRadians(c1.longitude);
double lat1 = degreesToRadians(90 - c1.latitude);
double long2 = degreesToRadians(c2.longitude);
double lat2 = degreesToRadians(90 - c2.latitude);
double gamma = fabs(long1 - long2);
if (gamma > M_PI) {
gamma = 2 * M_PI - gamma;
}
double result = cos(lat2) * cos(lat1) + sin(lat2) * sin(lat1) * cos(gamma);
return acos(result) * 6366.1977; // Kilometers
};
CGFloat degreesToRadians(CGFloat degrees) {
return degrees * M_PI / 180;
};
UPDATE: Use distanceFromLocation - Calculate distance between two points instead