问题描述
我有一个问题,我一直试图解决的问题一个月现在一次又一次失败的结果。我发现了一些类似于这个问题的各种问题,但没有任何东西让我明白答案。
b 。简而言之,我需要知道的是GPS坐标是在椭圆上还是椭圆内。
知识:
- 椭圆的宽度(以米为单位)
- 椭圆的高度(以米为单位)
- 椭圆中心的GPS坐标(在坐标系统中推测[0,0])
- 测试点的GPS坐标
- 测试点的角度
- 与测试点的距离
UNKNOWNS / NEEDS :
请帮助,因为某些原因,我无法将我的大脑包裹在这个数学中。
更新:
要添加更多信息,这些值在事物的宏观方案中都很小。例如:
如果用户想知道另一个用户是否进入了一些公园/场/地理围栏区域或其他类型的物理区域,在这种情况下,物理区域被设计为一个椭圆。
另外,这是用Objective-C编写的。下面,你会看到一个随机的+90度,这是作为基础机制看到0度作为北(导航),当我想它是单位圆正常。
$ p
$ b $ $ p $ - (BOOL)isLocation:(CLLocation *)locationEllipse :()椭圆*)椭圆
{
BOOL locationIsWithinEllipse = NO;
double ellipseWidth = ellipse.width;
double ellipseHeight = ellipse.height;
CLLocationDegrees locationAngleDegrees = 360 - ((int)([self headingBetweenCoordinate1:location.coordinate coordinate2:ellipse.locationCenter.coordinate] + 90)%360); //反转方向
double xOffsetInMeters =(ellipseWidth / 2)* COS(DEGREES_TO_RADIANS(locationAngleDegrees));
double yOffsetInMeters =(ellipseHeight / 2)* SIN(DEGREES_TO_RADIANS(locationAngleDegrees));
//下面的逻辑当前将抓取右上角的点,就好像它是一个盒子,而不是椭圆上的点
// This是事情破裂的地方。我需要这个角度(locationAngleDegrees)
//在椭圆上获取测试点标题上的坐标
CLLocationDegrees pointLat = [ ellipse.locationCenter addToLocationDistanceInMeters:yOffsetInMeters withBearingInDegrees:0] .coordinate.latitude;
CLLocationDegrees pointLong = [ellipse.locationCenter addToLocationDistanceInMeters:xOffsetInMeters withBearingInDegrees:90] .coordinate.longitude;
CLLocation * testPointOnEllipseLocation = [[CLLocation alloc] initWithLatitude:pointLat longitude:pointLong];
//只需检查测试点是否比椭圆点的距离更近
if(ABS([location distanceFromLocation:ellipse .locationCenter]) {
locationIsWithinEllipse = YES;
}
return locationIsWithinEllipse;
}
更新:
我仍然试图让这个数学正确。我明白如何用学校数学来完成它,但我怎样才能将它应用到我的代码中?此外,我严重不明白所有这些旋转的东西,因为我已经写了所有的代码,以不知道任何旋转。我相信这一切都是在苹果的低层位置上处理的。
任何人都可以请协助吗?
我已经通过Google的一些数学计算和(非常有帮助的)以下问题的指导解决了这个问题:
我也使用这个参考来进行Foci计算:
引用来自Cody的链接,主要逻辑:
我的椭圆比较小,所以我认为它是一个真正的(扁平)椭圆。我能够找到椭圆焦点的纬度,然后如果距离每个焦点的兴趣点小于2a(主轴半径),那么它在椭圆内。
我很欣赏提出的建议!谢谢!
Ok, so I am still new to asking questions on Stack Overflow, so please be nice :)
I have an issue that I have been trying to solve for a month now with failed results time and time again. I have found various questions somewhat similar to this, but nothing that has struck me as the definitive answer.
The closest that I have found so far is this:Convert GPS coordinates to coordinate plane.
In short, what I need is to know is if a GPS Coordinate is either on or inside an ellipse.
KNOWNS:
- Width of Ellipse in meters
- Height of Ellipse in meters
- GPS coordinate of Ellipse center (Presumably [0,0] on a coordinate system)
- GPS coordinate of test point
- Angle of point to test
- Distance to test point
UNKNOWNS / NEEDS:
- GPS Coordinate of point on ellipse with test point angle
- Distance to point on ellipse with test point angle
Please assist as for some reason, I just cannot wrap my brain around this math.
UPDATE:To add more information, the values are all quite small in the grand scheme of things.
As an example:If a user wants to know if another user has entered some park/field/geofenced area or some other type of physical area. The physical area in this case is designed as an Ellipse.
As an addition, this is written in Objective-C. Below, you will see a random "+90" degrees, this is there as the mechanisms underlying see 0 degrees as North (Navigation) when I want it to be the Unit-Circle "Normal" .
Associated Code with Discussion:
- (BOOL)isLocation:(CLLocation *)location withinEllipse:(Ellipse *)ellipse
{
BOOL locationIsWithinEllipse = NO;
double ellipseWidth = ellipse.width;
double ellipseHeight = ellipse.height;
CLLocationDegrees locationAngleDegrees = 360 - ((int)([self headingBetweenCoordinate1:location.coordinate coordinate2:ellipse.locationCenter.coordinate] + 90) % 360);//Invert Direction
double xOffsetInMeters = (ellipseWidth/2) * COS(DEGREES_TO_RADIANS(locationAngleDegrees));
double yOffsetInMeters = (ellipseHeight/2) * SIN(DEGREES_TO_RADIANS(locationAngleDegrees));
// The logic below will currently grab the Top-Right point as if it were a box, not the point on the Ellipse,
// This is where things are broken. I need this to be the GPS Coordinate of the Point on the Ellipse with angle (locationAngleDegrees)
// Grab the Coordinate on the Ellipse in the heading of the Test Point
CLLocationDegrees pointLat = [ellipse.locationCenter addToLocationDistanceInMeters:yOffsetInMeters withBearingInDegrees:0].coordinate.latitude;
CLLocationDegrees pointLong = [ellipse.locationCenter addToLocationDistanceInMeters:xOffsetInMeters withBearingInDegrees:90].coordinate.longitude;
CLLocation * testPointOnEllipseLocation = [[CLLocation alloc] initWithLatitude:pointLat longitude:pointLong];
// Just check if the Test Point is closer than the Distance of the Ellipse Point
if(ABS([location distanceFromLocation:ellipse.locationCenter]) <= ABS([testPointOnEllipseLocation distanceFromLocation:ellipse.locationCenter]))
{
locationIsWithinEllipse = YES;
}
return locationIsWithinEllipse;
}
UPDATE:
I am still trying to get this math correct. I understand how to get it done with "school math", but how can I apply that to my code in the example? Also, I seriously don't understand all of this rotation stuff as I have written all of my code to be agnostic of any rotation. I believe that is all handled in Apple's low-level location stuff.
Can anyone please assist?
I have solved this by using some mathematical calculations from Google and guidance from the (very helpful) following question:How to determine if a latitude & longitude is within an ellipse
I also used this reference for the Foci calculations: http://www.mathopenref.com/ellipsefoci.html
To quote, from Cody in the link, the primary logic:"My ellipse is relatively small so I assumed it was a true (flat) ellipse. I was able to locate the lat lon of the foci of the ellipse then if the sum of the distances from the point of interest to each focus is less than 2a (the major axis radius), then it is within the ellipse."
I do appreciate the suggestions presented! Thank You!
这篇关于我如何确定GPS坐标是在椭圆上还是在椭圆中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!