Check if latitude & longitude coordinates are inside a specific range of a latitude longitude polygon
$begingroup$
Since I'm not a mathematician I came here to ask what the most efficient way is to check if latitude and longitude coordinates are inside a range (for example 50 meters) of multiple latitude and longitude points (polygon).
I have a list of these longitude and latitude points:
[6.38537265,51.87721088],[6.38542453,51.87737201],[6.38523252,51.87739419],[6.38477205,51.87745015],[6.38426164,51.87751088],[6.38391099,51.87755068],[6.38386033,51.87738808],[6.38380232,51.87720004],[6.38376297,51.87708017],[6.38375183,51.87704018],[6.38373055,51.8769829],[6.38390723,51.87695904],[6.38389144,51.87691388],[6.38403002,51.87690001],[6.38440124,51.8768538],[6.38493939,51.87678787],[6.38522535,51.87675316],[6.38529885,51.87697928],[6.38537265,51.87721088]
And would like to check if these coordinates are in the range:
51.877368,6.383818
Here's a sketch of my question to visualize what I mean.
Arrows represent a given latitude and longitude combination.
Click here for the image of my sketch
I was planning to use the haversine formula but I do not know how I could use that in a list of multiple points.
Thanks in advance!
polygons
$endgroup$
|
show 9 more comments
$begingroup$
Since I'm not a mathematician I came here to ask what the most efficient way is to check if latitude and longitude coordinates are inside a range (for example 50 meters) of multiple latitude and longitude points (polygon).
I have a list of these longitude and latitude points:
[6.38537265,51.87721088],[6.38542453,51.87737201],[6.38523252,51.87739419],[6.38477205,51.87745015],[6.38426164,51.87751088],[6.38391099,51.87755068],[6.38386033,51.87738808],[6.38380232,51.87720004],[6.38376297,51.87708017],[6.38375183,51.87704018],[6.38373055,51.8769829],[6.38390723,51.87695904],[6.38389144,51.87691388],[6.38403002,51.87690001],[6.38440124,51.8768538],[6.38493939,51.87678787],[6.38522535,51.87675316],[6.38529885,51.87697928],[6.38537265,51.87721088]
And would like to check if these coordinates are in the range:
51.877368,6.383818
Here's a sketch of my question to visualize what I mean.
Arrows represent a given latitude and longitude combination.
Click here for the image of my sketch
I was planning to use the haversine formula but I do not know how I could use that in a list of multiple points.
Thanks in advance!
polygons
$endgroup$
$begingroup$
So does "in range of a point" mean that the distance to a point is smaller than some fixed value? I don't see what this has to do with polygons ...
$endgroup$
– Matti P.
Dec 5 '18 at 14:08
$begingroup$
@MattiP. Yes, well I'm trying to check if the given latitude and longitude is within the fixed value (50 meters) of the polygon (made of multiple latitude and longitude coordinates).
$endgroup$
– SaltyPotato
Dec 5 '18 at 14:14
$begingroup$
I want to ask you to give an answer to a sample problem so that I can know what you're trying to do. Suppose the input polygon is a triangle, all three vertices are on the equator, spaced 120 degrees apart. Is the north pole within this polygon? Is the south pole within it?
$endgroup$
– John Hughes
Dec 5 '18 at 14:20
$begingroup$
I'm wondering whether you care about the interior of the polygon at all. Perhaps your polygon is more a "poly-line", a sequence of segments that doesn't necessarily close up, and you want to know whether some test-point is within a distance $d$ of any point on this polyline. Is that in fact your question? I can imagine this being useful in navigational software ("Did the boat ever pass within 50 meters of mark "RB2"?").
$endgroup$
– John Hughes
Dec 5 '18 at 14:21
$begingroup$
By the way, you're likely to get several more comments trying to clarify your question -- that may be the toughest part of the process. I can say with some confidence that if your real question is any of the several that I can imagine, then it won't be too hard to solve it. But I'm not willing to solve every possible question that might be the one you're asking (and nor are others), hence these comments asking for clarifications.
$endgroup$
– John Hughes
Dec 5 '18 at 14:24
|
show 9 more comments
$begingroup$
Since I'm not a mathematician I came here to ask what the most efficient way is to check if latitude and longitude coordinates are inside a range (for example 50 meters) of multiple latitude and longitude points (polygon).
I have a list of these longitude and latitude points:
[6.38537265,51.87721088],[6.38542453,51.87737201],[6.38523252,51.87739419],[6.38477205,51.87745015],[6.38426164,51.87751088],[6.38391099,51.87755068],[6.38386033,51.87738808],[6.38380232,51.87720004],[6.38376297,51.87708017],[6.38375183,51.87704018],[6.38373055,51.8769829],[6.38390723,51.87695904],[6.38389144,51.87691388],[6.38403002,51.87690001],[6.38440124,51.8768538],[6.38493939,51.87678787],[6.38522535,51.87675316],[6.38529885,51.87697928],[6.38537265,51.87721088]
And would like to check if these coordinates are in the range:
51.877368,6.383818
Here's a sketch of my question to visualize what I mean.
Arrows represent a given latitude and longitude combination.
Click here for the image of my sketch
I was planning to use the haversine formula but I do not know how I could use that in a list of multiple points.
Thanks in advance!
polygons
$endgroup$
Since I'm not a mathematician I came here to ask what the most efficient way is to check if latitude and longitude coordinates are inside a range (for example 50 meters) of multiple latitude and longitude points (polygon).
I have a list of these longitude and latitude points:
[6.38537265,51.87721088],[6.38542453,51.87737201],[6.38523252,51.87739419],[6.38477205,51.87745015],[6.38426164,51.87751088],[6.38391099,51.87755068],[6.38386033,51.87738808],[6.38380232,51.87720004],[6.38376297,51.87708017],[6.38375183,51.87704018],[6.38373055,51.8769829],[6.38390723,51.87695904],[6.38389144,51.87691388],[6.38403002,51.87690001],[6.38440124,51.8768538],[6.38493939,51.87678787],[6.38522535,51.87675316],[6.38529885,51.87697928],[6.38537265,51.87721088]
And would like to check if these coordinates are in the range:
51.877368,6.383818
Here's a sketch of my question to visualize what I mean.
Arrows represent a given latitude and longitude combination.
Click here for the image of my sketch
I was planning to use the haversine formula but I do not know how I could use that in a list of multiple points.
Thanks in advance!
polygons
polygons
edited Dec 5 '18 at 15:22
SaltyPotato
asked Dec 5 '18 at 14:00
SaltyPotatoSaltyPotato
32
32
$begingroup$
So does "in range of a point" mean that the distance to a point is smaller than some fixed value? I don't see what this has to do with polygons ...
$endgroup$
– Matti P.
Dec 5 '18 at 14:08
$begingroup$
@MattiP. Yes, well I'm trying to check if the given latitude and longitude is within the fixed value (50 meters) of the polygon (made of multiple latitude and longitude coordinates).
$endgroup$
– SaltyPotato
Dec 5 '18 at 14:14
$begingroup$
I want to ask you to give an answer to a sample problem so that I can know what you're trying to do. Suppose the input polygon is a triangle, all three vertices are on the equator, spaced 120 degrees apart. Is the north pole within this polygon? Is the south pole within it?
$endgroup$
– John Hughes
Dec 5 '18 at 14:20
$begingroup$
I'm wondering whether you care about the interior of the polygon at all. Perhaps your polygon is more a "poly-line", a sequence of segments that doesn't necessarily close up, and you want to know whether some test-point is within a distance $d$ of any point on this polyline. Is that in fact your question? I can imagine this being useful in navigational software ("Did the boat ever pass within 50 meters of mark "RB2"?").
$endgroup$
– John Hughes
Dec 5 '18 at 14:21
$begingroup$
By the way, you're likely to get several more comments trying to clarify your question -- that may be the toughest part of the process. I can say with some confidence that if your real question is any of the several that I can imagine, then it won't be too hard to solve it. But I'm not willing to solve every possible question that might be the one you're asking (and nor are others), hence these comments asking for clarifications.
$endgroup$
– John Hughes
Dec 5 '18 at 14:24
|
show 9 more comments
$begingroup$
So does "in range of a point" mean that the distance to a point is smaller than some fixed value? I don't see what this has to do with polygons ...
$endgroup$
– Matti P.
Dec 5 '18 at 14:08
$begingroup$
@MattiP. Yes, well I'm trying to check if the given latitude and longitude is within the fixed value (50 meters) of the polygon (made of multiple latitude and longitude coordinates).
$endgroup$
– SaltyPotato
Dec 5 '18 at 14:14
$begingroup$
I want to ask you to give an answer to a sample problem so that I can know what you're trying to do. Suppose the input polygon is a triangle, all three vertices are on the equator, spaced 120 degrees apart. Is the north pole within this polygon? Is the south pole within it?
$endgroup$
– John Hughes
Dec 5 '18 at 14:20
$begingroup$
I'm wondering whether you care about the interior of the polygon at all. Perhaps your polygon is more a "poly-line", a sequence of segments that doesn't necessarily close up, and you want to know whether some test-point is within a distance $d$ of any point on this polyline. Is that in fact your question? I can imagine this being useful in navigational software ("Did the boat ever pass within 50 meters of mark "RB2"?").
$endgroup$
– John Hughes
Dec 5 '18 at 14:21
$begingroup$
By the way, you're likely to get several more comments trying to clarify your question -- that may be the toughest part of the process. I can say with some confidence that if your real question is any of the several that I can imagine, then it won't be too hard to solve it. But I'm not willing to solve every possible question that might be the one you're asking (and nor are others), hence these comments asking for clarifications.
$endgroup$
– John Hughes
Dec 5 '18 at 14:24
$begingroup$
So does "in range of a point" mean that the distance to a point is smaller than some fixed value? I don't see what this has to do with polygons ...
$endgroup$
– Matti P.
Dec 5 '18 at 14:08
$begingroup$
So does "in range of a point" mean that the distance to a point is smaller than some fixed value? I don't see what this has to do with polygons ...
$endgroup$
– Matti P.
Dec 5 '18 at 14:08
$begingroup$
@MattiP. Yes, well I'm trying to check if the given latitude and longitude is within the fixed value (50 meters) of the polygon (made of multiple latitude and longitude coordinates).
$endgroup$
– SaltyPotato
Dec 5 '18 at 14:14
$begingroup$
@MattiP. Yes, well I'm trying to check if the given latitude and longitude is within the fixed value (50 meters) of the polygon (made of multiple latitude and longitude coordinates).
$endgroup$
– SaltyPotato
Dec 5 '18 at 14:14
$begingroup$
I want to ask you to give an answer to a sample problem so that I can know what you're trying to do. Suppose the input polygon is a triangle, all three vertices are on the equator, spaced 120 degrees apart. Is the north pole within this polygon? Is the south pole within it?
$endgroup$
– John Hughes
Dec 5 '18 at 14:20
$begingroup$
I want to ask you to give an answer to a sample problem so that I can know what you're trying to do. Suppose the input polygon is a triangle, all three vertices are on the equator, spaced 120 degrees apart. Is the north pole within this polygon? Is the south pole within it?
$endgroup$
– John Hughes
Dec 5 '18 at 14:20
$begingroup$
I'm wondering whether you care about the interior of the polygon at all. Perhaps your polygon is more a "poly-line", a sequence of segments that doesn't necessarily close up, and you want to know whether some test-point is within a distance $d$ of any point on this polyline. Is that in fact your question? I can imagine this being useful in navigational software ("Did the boat ever pass within 50 meters of mark "RB2"?").
$endgroup$
– John Hughes
Dec 5 '18 at 14:21
$begingroup$
I'm wondering whether you care about the interior of the polygon at all. Perhaps your polygon is more a "poly-line", a sequence of segments that doesn't necessarily close up, and you want to know whether some test-point is within a distance $d$ of any point on this polyline. Is that in fact your question? I can imagine this being useful in navigational software ("Did the boat ever pass within 50 meters of mark "RB2"?").
$endgroup$
– John Hughes
Dec 5 '18 at 14:21
$begingroup$
By the way, you're likely to get several more comments trying to clarify your question -- that may be the toughest part of the process. I can say with some confidence that if your real question is any of the several that I can imagine, then it won't be too hard to solve it. But I'm not willing to solve every possible question that might be the one you're asking (and nor are others), hence these comments asking for clarifications.
$endgroup$
– John Hughes
Dec 5 '18 at 14:24
$begingroup$
By the way, you're likely to get several more comments trying to clarify your question -- that may be the toughest part of the process. I can say with some confidence that if your real question is any of the several that I can imagine, then it won't be too hard to solve it. But I'm not willing to solve every possible question that might be the one you're asking (and nor are others), hence these comments asking for clarifications.
$endgroup$
– John Hughes
Dec 5 '18 at 14:24
|
show 9 more comments
1 Answer
1
active
oldest
votes
$begingroup$
This is the start of a general answer, but not yet complete. Still, I'm going to save it and continue work later, in part because I believe that the careful reformulation of the problem may well be the largest contribution I can make.
Presumably you're doing this in software. So I'm gonna write pseudocode in a matlab-like language. It's not pretty, but it'll do.
Inputs:
r: The radius of the spherical approximation of earth, in some units
d: the distance that the test point needs to be within to produce "true"; same units.
p: an n x 2 array of points on the sphere, in lat/lon coordinates, with
90 degrees being the north pole, -90 being the south pole, etc.
q: a 1 x 2 array consisting of the lat and lon of the "user" or "test point"
Assumptions:
1. The earth is spherical enough, and the terrain flat enough, that lat-lon
distance between points is a good approximation of absolute distance. A
failure-case for this would be at half-dome in Yosemite, where two people could be
100 yards apart when radially projected onto the spherical approximation of the
earth, but many hundreds of yards apart in reality, one at the top of half-
dome, the other standing on the ground below.
2. The polygon defined by the points in the array p is defined so that
traversing the polygon edges in the order p1, p2, p3, ..., the interior
of the polygon is always to our left. There are no duplicated points,
and the polygon forms a simple closed curve on the surface (i.e., there are
no self-intersections).
3. No two points of the polygon are more than 90 degrees distant on the
sphere (I'm not certain I'll use this, but just in case...); the entire
polygon is contained within some hemisphere (also not sure i need this,
but...)
4. The test-point is within a distance of 90 degrees of all the polygon
vertices.
5. If the input points are written in degrees, then the cosine and sine and
other trig functions work with degrees; if the inputs are in radians, then
trig functions work with radians.
Output: TRUE if either one of the following two conditions holds:
A. the test point q is within the polygon defined by the points p OR
B. q is within spherical distance d of one of the polygon edges
and FALSE otherwise.
// ---- A few helper functions ----
// convert lat-lon coordinates into an xyz triple representing the
// corresponding point on the unit sphere.
function [x, y, z] = rect_from_polar(lat, lon)
y = sin(lat);
x = cos(lat) * cos(lon);
z = cos(lat) * sin(lon);
function [lat, lon] = polar_from_rect(x, y, z)
lat = arcsin(y);
if (y == 1) or (y == -1) {
lon = 0;
}
else {
lon = atan2(z, x);
}
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3027097%2fcheck-if-latitude-longitude-coordinates-are-inside-a-specific-range-of-a-latit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
This is the start of a general answer, but not yet complete. Still, I'm going to save it and continue work later, in part because I believe that the careful reformulation of the problem may well be the largest contribution I can make.
Presumably you're doing this in software. So I'm gonna write pseudocode in a matlab-like language. It's not pretty, but it'll do.
Inputs:
r: The radius of the spherical approximation of earth, in some units
d: the distance that the test point needs to be within to produce "true"; same units.
p: an n x 2 array of points on the sphere, in lat/lon coordinates, with
90 degrees being the north pole, -90 being the south pole, etc.
q: a 1 x 2 array consisting of the lat and lon of the "user" or "test point"
Assumptions:
1. The earth is spherical enough, and the terrain flat enough, that lat-lon
distance between points is a good approximation of absolute distance. A
failure-case for this would be at half-dome in Yosemite, where two people could be
100 yards apart when radially projected onto the spherical approximation of the
earth, but many hundreds of yards apart in reality, one at the top of half-
dome, the other standing on the ground below.
2. The polygon defined by the points in the array p is defined so that
traversing the polygon edges in the order p1, p2, p3, ..., the interior
of the polygon is always to our left. There are no duplicated points,
and the polygon forms a simple closed curve on the surface (i.e., there are
no self-intersections).
3. No two points of the polygon are more than 90 degrees distant on the
sphere (I'm not certain I'll use this, but just in case...); the entire
polygon is contained within some hemisphere (also not sure i need this,
but...)
4. The test-point is within a distance of 90 degrees of all the polygon
vertices.
5. If the input points are written in degrees, then the cosine and sine and
other trig functions work with degrees; if the inputs are in radians, then
trig functions work with radians.
Output: TRUE if either one of the following two conditions holds:
A. the test point q is within the polygon defined by the points p OR
B. q is within spherical distance d of one of the polygon edges
and FALSE otherwise.
// ---- A few helper functions ----
// convert lat-lon coordinates into an xyz triple representing the
// corresponding point on the unit sphere.
function [x, y, z] = rect_from_polar(lat, lon)
y = sin(lat);
x = cos(lat) * cos(lon);
z = cos(lat) * sin(lon);
function [lat, lon] = polar_from_rect(x, y, z)
lat = arcsin(y);
if (y == 1) or (y == -1) {
lon = 0;
}
else {
lon = atan2(z, x);
}
$endgroup$
add a comment |
$begingroup$
This is the start of a general answer, but not yet complete. Still, I'm going to save it and continue work later, in part because I believe that the careful reformulation of the problem may well be the largest contribution I can make.
Presumably you're doing this in software. So I'm gonna write pseudocode in a matlab-like language. It's not pretty, but it'll do.
Inputs:
r: The radius of the spherical approximation of earth, in some units
d: the distance that the test point needs to be within to produce "true"; same units.
p: an n x 2 array of points on the sphere, in lat/lon coordinates, with
90 degrees being the north pole, -90 being the south pole, etc.
q: a 1 x 2 array consisting of the lat and lon of the "user" or "test point"
Assumptions:
1. The earth is spherical enough, and the terrain flat enough, that lat-lon
distance between points is a good approximation of absolute distance. A
failure-case for this would be at half-dome in Yosemite, where two people could be
100 yards apart when radially projected onto the spherical approximation of the
earth, but many hundreds of yards apart in reality, one at the top of half-
dome, the other standing on the ground below.
2. The polygon defined by the points in the array p is defined so that
traversing the polygon edges in the order p1, p2, p3, ..., the interior
of the polygon is always to our left. There are no duplicated points,
and the polygon forms a simple closed curve on the surface (i.e., there are
no self-intersections).
3. No two points of the polygon are more than 90 degrees distant on the
sphere (I'm not certain I'll use this, but just in case...); the entire
polygon is contained within some hemisphere (also not sure i need this,
but...)
4. The test-point is within a distance of 90 degrees of all the polygon
vertices.
5. If the input points are written in degrees, then the cosine and sine and
other trig functions work with degrees; if the inputs are in radians, then
trig functions work with radians.
Output: TRUE if either one of the following two conditions holds:
A. the test point q is within the polygon defined by the points p OR
B. q is within spherical distance d of one of the polygon edges
and FALSE otherwise.
// ---- A few helper functions ----
// convert lat-lon coordinates into an xyz triple representing the
// corresponding point on the unit sphere.
function [x, y, z] = rect_from_polar(lat, lon)
y = sin(lat);
x = cos(lat) * cos(lon);
z = cos(lat) * sin(lon);
function [lat, lon] = polar_from_rect(x, y, z)
lat = arcsin(y);
if (y == 1) or (y == -1) {
lon = 0;
}
else {
lon = atan2(z, x);
}
$endgroup$
add a comment |
$begingroup$
This is the start of a general answer, but not yet complete. Still, I'm going to save it and continue work later, in part because I believe that the careful reformulation of the problem may well be the largest contribution I can make.
Presumably you're doing this in software. So I'm gonna write pseudocode in a matlab-like language. It's not pretty, but it'll do.
Inputs:
r: The radius of the spherical approximation of earth, in some units
d: the distance that the test point needs to be within to produce "true"; same units.
p: an n x 2 array of points on the sphere, in lat/lon coordinates, with
90 degrees being the north pole, -90 being the south pole, etc.
q: a 1 x 2 array consisting of the lat and lon of the "user" or "test point"
Assumptions:
1. The earth is spherical enough, and the terrain flat enough, that lat-lon
distance between points is a good approximation of absolute distance. A
failure-case for this would be at half-dome in Yosemite, where two people could be
100 yards apart when radially projected onto the spherical approximation of the
earth, but many hundreds of yards apart in reality, one at the top of half-
dome, the other standing on the ground below.
2. The polygon defined by the points in the array p is defined so that
traversing the polygon edges in the order p1, p2, p3, ..., the interior
of the polygon is always to our left. There are no duplicated points,
and the polygon forms a simple closed curve on the surface (i.e., there are
no self-intersections).
3. No two points of the polygon are more than 90 degrees distant on the
sphere (I'm not certain I'll use this, but just in case...); the entire
polygon is contained within some hemisphere (also not sure i need this,
but...)
4. The test-point is within a distance of 90 degrees of all the polygon
vertices.
5. If the input points are written in degrees, then the cosine and sine and
other trig functions work with degrees; if the inputs are in radians, then
trig functions work with radians.
Output: TRUE if either one of the following two conditions holds:
A. the test point q is within the polygon defined by the points p OR
B. q is within spherical distance d of one of the polygon edges
and FALSE otherwise.
// ---- A few helper functions ----
// convert lat-lon coordinates into an xyz triple representing the
// corresponding point on the unit sphere.
function [x, y, z] = rect_from_polar(lat, lon)
y = sin(lat);
x = cos(lat) * cos(lon);
z = cos(lat) * sin(lon);
function [lat, lon] = polar_from_rect(x, y, z)
lat = arcsin(y);
if (y == 1) or (y == -1) {
lon = 0;
}
else {
lon = atan2(z, x);
}
$endgroup$
This is the start of a general answer, but not yet complete. Still, I'm going to save it and continue work later, in part because I believe that the careful reformulation of the problem may well be the largest contribution I can make.
Presumably you're doing this in software. So I'm gonna write pseudocode in a matlab-like language. It's not pretty, but it'll do.
Inputs:
r: The radius of the spherical approximation of earth, in some units
d: the distance that the test point needs to be within to produce "true"; same units.
p: an n x 2 array of points on the sphere, in lat/lon coordinates, with
90 degrees being the north pole, -90 being the south pole, etc.
q: a 1 x 2 array consisting of the lat and lon of the "user" or "test point"
Assumptions:
1. The earth is spherical enough, and the terrain flat enough, that lat-lon
distance between points is a good approximation of absolute distance. A
failure-case for this would be at half-dome in Yosemite, where two people could be
100 yards apart when radially projected onto the spherical approximation of the
earth, but many hundreds of yards apart in reality, one at the top of half-
dome, the other standing on the ground below.
2. The polygon defined by the points in the array p is defined so that
traversing the polygon edges in the order p1, p2, p3, ..., the interior
of the polygon is always to our left. There are no duplicated points,
and the polygon forms a simple closed curve on the surface (i.e., there are
no self-intersections).
3. No two points of the polygon are more than 90 degrees distant on the
sphere (I'm not certain I'll use this, but just in case...); the entire
polygon is contained within some hemisphere (also not sure i need this,
but...)
4. The test-point is within a distance of 90 degrees of all the polygon
vertices.
5. If the input points are written in degrees, then the cosine and sine and
other trig functions work with degrees; if the inputs are in radians, then
trig functions work with radians.
Output: TRUE if either one of the following two conditions holds:
A. the test point q is within the polygon defined by the points p OR
B. q is within spherical distance d of one of the polygon edges
and FALSE otherwise.
// ---- A few helper functions ----
// convert lat-lon coordinates into an xyz triple representing the
// corresponding point on the unit sphere.
function [x, y, z] = rect_from_polar(lat, lon)
y = sin(lat);
x = cos(lat) * cos(lon);
z = cos(lat) * sin(lon);
function [lat, lon] = polar_from_rect(x, y, z)
lat = arcsin(y);
if (y == 1) or (y == -1) {
lon = 0;
}
else {
lon = atan2(z, x);
}
answered Dec 5 '18 at 23:53
John HughesJohn Hughes
63k24090
63k24090
add a comment |
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3027097%2fcheck-if-latitude-longitude-coordinates-are-inside-a-specific-range-of-a-latit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
So does "in range of a point" mean that the distance to a point is smaller than some fixed value? I don't see what this has to do with polygons ...
$endgroup$
– Matti P.
Dec 5 '18 at 14:08
$begingroup$
@MattiP. Yes, well I'm trying to check if the given latitude and longitude is within the fixed value (50 meters) of the polygon (made of multiple latitude and longitude coordinates).
$endgroup$
– SaltyPotato
Dec 5 '18 at 14:14
$begingroup$
I want to ask you to give an answer to a sample problem so that I can know what you're trying to do. Suppose the input polygon is a triangle, all three vertices are on the equator, spaced 120 degrees apart. Is the north pole within this polygon? Is the south pole within it?
$endgroup$
– John Hughes
Dec 5 '18 at 14:20
$begingroup$
I'm wondering whether you care about the interior of the polygon at all. Perhaps your polygon is more a "poly-line", a sequence of segments that doesn't necessarily close up, and you want to know whether some test-point is within a distance $d$ of any point on this polyline. Is that in fact your question? I can imagine this being useful in navigational software ("Did the boat ever pass within 50 meters of mark "RB2"?").
$endgroup$
– John Hughes
Dec 5 '18 at 14:21
$begingroup$
By the way, you're likely to get several more comments trying to clarify your question -- that may be the toughest part of the process. I can say with some confidence that if your real question is any of the several that I can imagine, then it won't be too hard to solve it. But I'm not willing to solve every possible question that might be the one you're asking (and nor are others), hence these comments asking for clarifications.
$endgroup$
– John Hughes
Dec 5 '18 at 14:24