I have a database(PostgreSQL) with coordinates of lightning bolts.
I want coordinates inside a circumference sector(SQL Query). I have the radius, angle(Z) and point A of circumference, and coordinates of extremal points([lat1,lng1], [lat2, lng2]).
Thanks a lot!
Related
look at the picture above, see a black circle.
black circle Coordinates is lat(126.897453), lon(37.530028)
if the red rectangle is square(vertical and horizontal are 20m), I want to know the blue circle of coordinates
please let me know calculation formula.
In advance, thanks for your answer!
have a good time :)
This task is solved by first transforming the spherical lat/long coordinates to a cartesian x,y coordinates with unit meters.
Then you calculate the location with very basic addition. (x = x-20, y=y-20/2)
Then you transform the location back to lat/long coordinates.
I'm a libgdx NOOB - apologies if this is an obvious question..
Using libgdx I have set up a Perspective camera, looking at origin (camera near = 1f, far = 300f). Viewport extends across the entire screen.
Basically, I would like to know how to convert a 2D screen coordinate (x,y) to the 3D world coordinate (x, y, z) where the Z value is clamped to the camera's near plane.
I think I should use the camera.getPickRay method to get a picking ray for the screen coordinate. I should then get the intersection point of this ray and the camera's near plane to get the world coordinate of the point on the near plane.
I thought that the resulting Ray object's origin property was the near-plane intersection point I was after, but this doesn't seem to be the case.
Am I on the right track?
Camera#unproject() returns, depending on the z-value, the value between the near (z=0) and far plane (z=1), see the javadocs. Camera#getPickRay() sets the origin member to the unprojected value at z=0, thus on the near plane, see the code. If you don't need the ray (including the direction) then you don't have to calculate the pick ray, instead you can call the unproject method directly.
Vector3 pointOnNearPlane = camera.unproject(new Vector3(touchX, touchY, 0f));
Likewise, for the point on the far plane:
Vector3 pointOnFarPlane = camera.unproject(new Vector3(touchX, touchY, 1f));
I am trying to figure out if a latitude/longitude point is contained within a polygon defined by vertexes that represent points on the earth (also lat/lon's, in clockwise order). This is trivial for polygons that can be mapped to the 2D lat/lon space.
Where this becomes increasingly difficult is circle's (now switching back to 3D) that may go from pole to pole covering half the earth. The translation to lat/lon looks like a sine wave. The 2D point in polygon test no longer applies to this case. Is there an algorithm that exists that solves this problem?
================== Clarifications on comments below: ===================
The polygon is defined as (lon, lat) pairs in degrees, i.e., (60, 90), (60, 110), (-30, 110), (-30, 90).
I do have code that implements the ray casting algorithm, and that works. however, certain polygons on the surface of the earth do not translate to closed polygons in the 2D space.
As stated by denniston.t, if you are only interested in circles, and you have a radius, you can simply check if the Great Circle Distance between the center point and the point is less than the radius. To find the great circle distance you typically use the Haversine Formula. The following is my implementation in python:
from math import radians, sin, cos, asin, sqrt
def haversine(point1, point2):
"""Gives the distance between two points on earth.
The haversine formula, given two sets of latitude and longitude,
returns the distance along the surface of the earth in miles,
ignoring potential changes in elevation. The points must be in
decimal degrees.
"""
earth_radius_miles = 3956
lat1, lon1 = (radians(coord) for coord in point1)
lat2, lon2 = (radians(coord) for coord in point2)
dlat, dlon = (lat2 - lat1, lon2 - lon1)
a = sin(dlat/2.0)**2 + cos(lat1) * cos(lat2) * sin(dlon/2.0)**2
great_circle_distance = 2 * asin(min(1,sqrt(a)))
d = earth_radius_miles * great_circle_distance
return d
If you have the center point and radius of your circle drawn on the surface of the sphere, calculate the Great-circle distance between the center point and target point. If it's less than the radius of the circle, the target point lies in the circle.
This will not generalize to arbitrary polygons drawn on your sphere, but you only asked about circles, so I don't know if it matters to you.
containsLocation(point:LatLng, polygon:Polygon)
Working with iPhone and Objective C.
I am working on a game and I need to correctly reflect a ball off a circle object. I am trying to do it as a line and circle intersection. I have my ball position outside the circle and I have the new ball position that would be inside the circle at the next draw update. I know the intersect point of the line (ball path) and the circle. Now I want to rotate the ending point of the ball path about the intersection point to get the correct angle of reflection off the tangent.
The following are known:
ball current x,y
ball end x,y
ball radius
circle center x,y
circle radius
intersection point of ball path and circle x and y
I know I need to find the angle of incidence between the tangent line and the incoming ball path which will also equal my angle of reflection. I think once I know those two angles I can subtract them from 180 to get my rotation angle then rotate my end point about the angle of intersection by that amount. I just don't know how.
First, you should note that the center of the ball doesn't have to be inside of the circle to indicate that there's a reflection or bounce. As long as the distance between ball center and circle is less than the radius of the ball, there will be a bounce.
If the radius of the circle is R and the radius of the ball is r, things are simplified if you convert to the case where the circle has radius R+r and the ball has radius 0. For the purposes of collision detection and reflection/bouncing, this is equivalent.
If you have the point of intersection between the (enlarged) circle and the ball's path, you can easily compute the normal N to the circle at that point (it is the unit vector in the direction from the center of the circle to the collision point).
For an incoming vector V the reflected vector is V-2(N⋅V) N, where (N⋅V) is the dot product. For this problem, the incoming vector V is the vector from the intersection point to the point inside the circle.
As for the reflection formula given above, it is relatively easy to derive using vector math, but you can also Google search terms like "calculate reflection vector". The signs in the formula will vary with the assumed directions of V and N. Mathworld has a derivation although, as noted, the signs are different.
I only know the solution to the geometry part.
Let:
r1 => Radius of ball
r2 => Radius of circle
You can calculate the distance between the two circles by using Pythagoras theorem.
If the distance is less than the r1+r2 then do the collision.
For the collision,I would refer you Here. It's in python but I think it should give you an idea of what to do. Hopefully, even implement it in Objective C. The Tutorial By PeterCollingRidge.
I have two sets of Latitude/Longitude coordinates.
The first one is the coordinates of an equirectangular panorama picture.
The second one of a point in sight. So it is on the picture.
I need the x/y coordinates of the second point to draw it on the picture.
In javascript.
Example equirectangular panorama picture and application (using bearing and distance instead of Lat/Lon coordinates):
http://www.diy-streetview.org/data/development/20100121/streetview-playerA.html?streetview=small/001sm.jpg
Hints:
The horizon is half the hight of the image.
The camera was 2 meters above ground.
Image Direction is the middle of the image. Where it "looks to".
It's in the Netherlands, so a negative Altitude is no error. They are really below the waterline.
Skipp the camera hight and GPSAltitude when its to complicated.
A bit data:
001sm.jpg
GPSLatitude: 51.802104
GPSLongitude: 3.929393
GPSAltitude: 1.100000
GPS Image Direction = 260 degrees
002sm.jpg
GPSLatitude: 51.802082
GPSLongitude: 3.929200
GPSAltitude: -2.270000
GPS Image Direction = 265 degrees
003sm.jpg
GPSLatitude: 51.802082
GPSLongitude: 3.928986
GPSAltitude: -3.710000
GPS Image Direction = 275 degrees
004sm.jpg
GPSLatitude: 51.802104
GPSLongitude: 3.928771
GPSAltitude: -3.710000
GPS Image Direction = 270 degrees
Thanks,
Jan
janmartin AT diy-streetview DOT org