Calculation lat/long- points for a pentagon around center












1















I'm looking for a way to retrieve five points that would make a pentagon around a given center and a given distance.



Something like this:



getPentagonPoints = (latlng, distance) => {
var pentagonLatLng = ;
//magic calculations goes here
return pentagonLatLng;
}









share|improve this question























  • math.stackexchange.com/questions/1990504/…

    – nem035
    Jan 1 at 20:03











  • @nem035 I don't think that's directly applicable, since it's putting the figure on a plane, not a sphere.

    – Robert Dodier
    Jan 2 at 23:42
















1















I'm looking for a way to retrieve five points that would make a pentagon around a given center and a given distance.



Something like this:



getPentagonPoints = (latlng, distance) => {
var pentagonLatLng = ;
//magic calculations goes here
return pentagonLatLng;
}









share|improve this question























  • math.stackexchange.com/questions/1990504/…

    – nem035
    Jan 1 at 20:03











  • @nem035 I don't think that's directly applicable, since it's putting the figure on a plane, not a sphere.

    – Robert Dodier
    Jan 2 at 23:42














1












1








1








I'm looking for a way to retrieve five points that would make a pentagon around a given center and a given distance.



Something like this:



getPentagonPoints = (latlng, distance) => {
var pentagonLatLng = ;
//magic calculations goes here
return pentagonLatLng;
}









share|improve this question














I'm looking for a way to retrieve five points that would make a pentagon around a given center and a given distance.



Something like this:



getPentagonPoints = (latlng, distance) => {
var pentagonLatLng = ;
//magic calculations goes here
return pentagonLatLng;
}






javascript math latitude-longitude






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 19:51









David W.David W.

6034820




6034820













  • math.stackexchange.com/questions/1990504/…

    – nem035
    Jan 1 at 20:03











  • @nem035 I don't think that's directly applicable, since it's putting the figure on a plane, not a sphere.

    – Robert Dodier
    Jan 2 at 23:42



















  • math.stackexchange.com/questions/1990504/…

    – nem035
    Jan 1 at 20:03











  • @nem035 I don't think that's directly applicable, since it's putting the figure on a plane, not a sphere.

    – Robert Dodier
    Jan 2 at 23:42

















math.stackexchange.com/questions/1990504/…

– nem035
Jan 1 at 20:03





math.stackexchange.com/questions/1990504/…

– nem035
Jan 1 at 20:03













@nem035 I don't think that's directly applicable, since it's putting the figure on a plane, not a sphere.

– Robert Dodier
Jan 2 at 23:42





@nem035 I don't think that's directly applicable, since it's putting the figure on a plane, not a sphere.

– Robert Dodier
Jan 2 at 23:42












1 Answer
1






active

oldest

votes


















0














You can do it like this:






function getPentagonPoints(latlng, distance) {
var pentagonLatLng = ;
for (let i = 0; i < 5; i++) {
// Pi * 2 is 360 degrees, in radians
// We add 270 degrees (Pi * 1.5 radians) to start at the top
const angle = Math.PI * 2 / 5 * i + Math.PI * 1.5; // in radians
const lng = distance * Math.cos(angle) + latlng.lng;
const lat = distance * Math.sin(angle) + latlng.lat;
pentagonLatLng.push({lat, lng});
}
return pentagonLatLng;
}

// Just for the demo
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

const latLng = { lat: 90, lng: 200 };
const points = getPentagonPoints(latLng, 50);

points.forEach((point, i) => {
if (i === 0) { ctx.moveTo(point.lng, point.lat); }
ctx.lineTo(point.lng, point.lat);
if (i === points.length - 1) { ctx.lineTo(points[0].lng, points[0].lat); }
});

ctx.stroke();

<canvas width="400" height="160"></canvas>








share|improve this answer





















  • 1





    I think that's OK for a pentagon in the plane, but not on a sphere. (Since OP mentioned latitude and longitude it seems a sphere is implied.) It's probably OK for small pentagons not near the poles, but large pentagons and ones near the poles will be distorted. Maybe a way to go about it is to draw the figure on the equator and then rotate it to the desired latitude. Just guessing here.

    – Robert Dodier
    Jan 2 at 23:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998467%2fcalculation-lat-long-points-for-a-pentagon-around-center%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









0














You can do it like this:






function getPentagonPoints(latlng, distance) {
var pentagonLatLng = ;
for (let i = 0; i < 5; i++) {
// Pi * 2 is 360 degrees, in radians
// We add 270 degrees (Pi * 1.5 radians) to start at the top
const angle = Math.PI * 2 / 5 * i + Math.PI * 1.5; // in radians
const lng = distance * Math.cos(angle) + latlng.lng;
const lat = distance * Math.sin(angle) + latlng.lat;
pentagonLatLng.push({lat, lng});
}
return pentagonLatLng;
}

// Just for the demo
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

const latLng = { lat: 90, lng: 200 };
const points = getPentagonPoints(latLng, 50);

points.forEach((point, i) => {
if (i === 0) { ctx.moveTo(point.lng, point.lat); }
ctx.lineTo(point.lng, point.lat);
if (i === points.length - 1) { ctx.lineTo(points[0].lng, points[0].lat); }
});

ctx.stroke();

<canvas width="400" height="160"></canvas>








share|improve this answer





















  • 1





    I think that's OK for a pentagon in the plane, but not on a sphere. (Since OP mentioned latitude and longitude it seems a sphere is implied.) It's probably OK for small pentagons not near the poles, but large pentagons and ones near the poles will be distorted. Maybe a way to go about it is to draw the figure on the equator and then rotate it to the desired latitude. Just guessing here.

    – Robert Dodier
    Jan 2 at 23:49
















0














You can do it like this:






function getPentagonPoints(latlng, distance) {
var pentagonLatLng = ;
for (let i = 0; i < 5; i++) {
// Pi * 2 is 360 degrees, in radians
// We add 270 degrees (Pi * 1.5 radians) to start at the top
const angle = Math.PI * 2 / 5 * i + Math.PI * 1.5; // in radians
const lng = distance * Math.cos(angle) + latlng.lng;
const lat = distance * Math.sin(angle) + latlng.lat;
pentagonLatLng.push({lat, lng});
}
return pentagonLatLng;
}

// Just for the demo
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

const latLng = { lat: 90, lng: 200 };
const points = getPentagonPoints(latLng, 50);

points.forEach((point, i) => {
if (i === 0) { ctx.moveTo(point.lng, point.lat); }
ctx.lineTo(point.lng, point.lat);
if (i === points.length - 1) { ctx.lineTo(points[0].lng, points[0].lat); }
});

ctx.stroke();

<canvas width="400" height="160"></canvas>








share|improve this answer





















  • 1





    I think that's OK for a pentagon in the plane, but not on a sphere. (Since OP mentioned latitude and longitude it seems a sphere is implied.) It's probably OK for small pentagons not near the poles, but large pentagons and ones near the poles will be distorted. Maybe a way to go about it is to draw the figure on the equator and then rotate it to the desired latitude. Just guessing here.

    – Robert Dodier
    Jan 2 at 23:49














0












0








0







You can do it like this:






function getPentagonPoints(latlng, distance) {
var pentagonLatLng = ;
for (let i = 0; i < 5; i++) {
// Pi * 2 is 360 degrees, in radians
// We add 270 degrees (Pi * 1.5 radians) to start at the top
const angle = Math.PI * 2 / 5 * i + Math.PI * 1.5; // in radians
const lng = distance * Math.cos(angle) + latlng.lng;
const lat = distance * Math.sin(angle) + latlng.lat;
pentagonLatLng.push({lat, lng});
}
return pentagonLatLng;
}

// Just for the demo
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

const latLng = { lat: 90, lng: 200 };
const points = getPentagonPoints(latLng, 50);

points.forEach((point, i) => {
if (i === 0) { ctx.moveTo(point.lng, point.lat); }
ctx.lineTo(point.lng, point.lat);
if (i === points.length - 1) { ctx.lineTo(points[0].lng, points[0].lat); }
});

ctx.stroke();

<canvas width="400" height="160"></canvas>








share|improve this answer















You can do it like this:






function getPentagonPoints(latlng, distance) {
var pentagonLatLng = ;
for (let i = 0; i < 5; i++) {
// Pi * 2 is 360 degrees, in radians
// We add 270 degrees (Pi * 1.5 radians) to start at the top
const angle = Math.PI * 2 / 5 * i + Math.PI * 1.5; // in radians
const lng = distance * Math.cos(angle) + latlng.lng;
const lat = distance * Math.sin(angle) + latlng.lat;
pentagonLatLng.push({lat, lng});
}
return pentagonLatLng;
}

// Just for the demo
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

const latLng = { lat: 90, lng: 200 };
const points = getPentagonPoints(latLng, 50);

points.forEach((point, i) => {
if (i === 0) { ctx.moveTo(point.lng, point.lat); }
ctx.lineTo(point.lng, point.lat);
if (i === points.length - 1) { ctx.lineTo(points[0].lng, points[0].lat); }
});

ctx.stroke();

<canvas width="400" height="160"></canvas>








function getPentagonPoints(latlng, distance) {
var pentagonLatLng = ;
for (let i = 0; i < 5; i++) {
// Pi * 2 is 360 degrees, in radians
// We add 270 degrees (Pi * 1.5 radians) to start at the top
const angle = Math.PI * 2 / 5 * i + Math.PI * 1.5; // in radians
const lng = distance * Math.cos(angle) + latlng.lng;
const lat = distance * Math.sin(angle) + latlng.lat;
pentagonLatLng.push({lat, lng});
}
return pentagonLatLng;
}

// Just for the demo
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

const latLng = { lat: 90, lng: 200 };
const points = getPentagonPoints(latLng, 50);

points.forEach((point, i) => {
if (i === 0) { ctx.moveTo(point.lng, point.lat); }
ctx.lineTo(point.lng, point.lat);
if (i === points.length - 1) { ctx.lineTo(points[0].lng, points[0].lat); }
});

ctx.stroke();

<canvas width="400" height="160"></canvas>





function getPentagonPoints(latlng, distance) {
var pentagonLatLng = ;
for (let i = 0; i < 5; i++) {
// Pi * 2 is 360 degrees, in radians
// We add 270 degrees (Pi * 1.5 radians) to start at the top
const angle = Math.PI * 2 / 5 * i + Math.PI * 1.5; // in radians
const lng = distance * Math.cos(angle) + latlng.lng;
const lat = distance * Math.sin(angle) + latlng.lat;
pentagonLatLng.push({lat, lng});
}
return pentagonLatLng;
}

// Just for the demo
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');

const latLng = { lat: 90, lng: 200 };
const points = getPentagonPoints(latLng, 50);

points.forEach((point, i) => {
if (i === 0) { ctx.moveTo(point.lng, point.lat); }
ctx.lineTo(point.lng, point.lat);
if (i === points.length - 1) { ctx.lineTo(points[0].lng, points[0].lat); }
});

ctx.stroke();

<canvas width="400" height="160"></canvas>






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 20:28

























answered Jan 1 at 20:14









blexblex

12.4k12245




12.4k12245








  • 1





    I think that's OK for a pentagon in the plane, but not on a sphere. (Since OP mentioned latitude and longitude it seems a sphere is implied.) It's probably OK for small pentagons not near the poles, but large pentagons and ones near the poles will be distorted. Maybe a way to go about it is to draw the figure on the equator and then rotate it to the desired latitude. Just guessing here.

    – Robert Dodier
    Jan 2 at 23:49














  • 1





    I think that's OK for a pentagon in the plane, but not on a sphere. (Since OP mentioned latitude and longitude it seems a sphere is implied.) It's probably OK for small pentagons not near the poles, but large pentagons and ones near the poles will be distorted. Maybe a way to go about it is to draw the figure on the equator and then rotate it to the desired latitude. Just guessing here.

    – Robert Dodier
    Jan 2 at 23:49








1




1





I think that's OK for a pentagon in the plane, but not on a sphere. (Since OP mentioned latitude and longitude it seems a sphere is implied.) It's probably OK for small pentagons not near the poles, but large pentagons and ones near the poles will be distorted. Maybe a way to go about it is to draw the figure on the equator and then rotate it to the desired latitude. Just guessing here.

– Robert Dodier
Jan 2 at 23:49





I think that's OK for a pentagon in the plane, but not on a sphere. (Since OP mentioned latitude and longitude it seems a sphere is implied.) It's probably OK for small pentagons not near the poles, but large pentagons and ones near the poles will be distorted. Maybe a way to go about it is to draw the figure on the equator and then rotate it to the desired latitude. Just guessing here.

– Robert Dodier
Jan 2 at 23:49




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998467%2fcalculation-lat-long-points-for-a-pentagon-around-center%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement