I have an application that generates points on edge of a sphere. They're recorded as Lat/Lon coordinates in degrees or radians (example is degrees).
I am unable to figure out how to display them on a cartesian plane as viewed from a point external to the sphere (imagine a satellite photographing earth).
In the example below I have 8 points (2 sets of four points at different latitudes encompassing the sphere). I have manually plotted them roughly as you would see these from two angles - one above the 'north pole' and one above a point on the 'equator'.
In this example the top down view would see all 8 points cleanly but the side view would have overlapping points assuming the sphere is transparent.
I'm not 100% sure but I suspect the 'height' of viewing agent above the sphere is relevant so having that as a variable would seem valid.
I expect the function would be something like this:
function translateSpherePoint(sphereRadius, pointLat, pointLon, viewX, viewY, viewZ){
//magic code
return {newPointX, newPointY}
}
I've been studying this at length: https://www.movable-type.co.uk/scripts/latlong.html and this has proven very useful but is primarily for point manipulation on the sphere - not so much for viewing.
var canvas = document.getElementById("mainCanvas");
var ctx = canvas.getContext('2d');
canvas.width = 500; canvas.height = 400; ctx.font = "20px Georgia";
ctx.fillText("Top down view", 25, 50);
ctx.fillText("Side view", 25+250, 50);
let points = [
//points half way between the equator and north pole
{point: 1, latDeg:45, lonDeg:45},
{point: 2, latDeg:45, lonDeg:135},
{point: 3, latDeg:45, lonDeg:-135},
{point: 4, latDeg:45, lonDeg:-45},
//points 3/4 of the way between the equator and the north pole
{point: 5, latDeg:67.5, lonDeg:45},
{point: 6, latDeg:67.5, lonDeg:135},
{point: 7, latDeg:67.5, lonDeg:-135},
{point: 8, latDeg:67.5, lonDeg:-45}
]
ctx.font = "13px Georgia";
//Top Down View
ctx.beginPath();
ctx.arc(100,200,100,0,2*Math.PI);
ctx.stroke();ctx.beginPath();
ctx.arc(100-50,200-50,10,0,2*Math.PI); ctx.fillText("1", 100-50-4, 200-50+3);
ctx.stroke();ctx.beginPath();
ctx.arc(100+50,200-50,10,0,2*Math.PI); ctx.fillText("2", 100+50-4, 200-50+3);
ctx.stroke();ctx.beginPath();
ctx.arc(100+50,200+50,10,0,2*Math.PI); ctx.fillText("3", 100+50-4, 200+50+3);
ctx.stroke();ctx.beginPath();
ctx.arc(100-50,200+50,10,0,2*Math.PI); ctx.fillText("4", 100-50-4, 200+50+3);
ctx.stroke();ctx.beginPath();
ctx.arc(100-25,200-25,10,0,2*Math.PI); ctx.fillText("5", 100-25-4, 200-25+3);
ctx.stroke();ctx.beginPath();
ctx.arc(100+25,200-25,10,0,2*Math.PI); ctx.fillText("6", 100+25-4, 200-25+3);
ctx.stroke();ctx.beginPath();
ctx.arc(100+25,200+25,10,0,2*Math.PI); ctx.fillText("7", 100+25-4, 200+25+3);
ctx.stroke();ctx.beginPath();
ctx.arc(100-25,200+25,10,0,2*Math.PI); ctx.fillText("8", 100-25-4, 200+25+3);
ctx.stroke();ctx.beginPath();
//Side View
ctx.beginPath();
ctx.arc(350,200,100,0,2*Math.PI);
ctx.stroke();ctx.beginPath();
ctx.arc(350-50,200-50,10,0,2*Math.PI); ctx.fillText("1/4", 350-50-10, 200-50+3);
ctx.stroke();ctx.beginPath();
ctx.arc(350+50,200-50,10,0,2*Math.PI); ctx.fillText("2/3", 350+50-10, 200-50+3);
ctx.stroke();ctx.beginPath();
ctx.arc(350-25,200-75,10,0,2*Math.PI); ctx.fillText("5/8", 350-25-10, 200-75+3);
ctx.stroke();ctx.beginPath();
ctx.arc(350+25,200-75,10,0,2*Math.PI); ctx.fillText("6/7", 350+25-10, 200-75+3);
ctx.stroke();ctx.beginPath();
<canvas id="mainCanvas"> </canvas>
My theory is to use the new viewpoint to translate a new cartesian plane and return the xy values relative to that new plane. An example is in my graph