2

First off apologies for the crude drawing, I am by no means well versed in 3D manipulation and have only a very basic understanding of matrices, so please explain everything as clearly as you can and make no assumptions of my level of knowledge.

I am currently gathering longitude and latitude data and converting it into Cartesian X,Y and Z with the following function:

public CartesianXYZ LonLat2Cartesian(double lon, double lat)
{
    CartesianXYZ XYZ = new CartesianXYZ();
    var R = 6371000;
    XYZ.X = Convert.ToInt32(R * Math.Cos(lat) * Math.Cos(lon));
    XYZ.Y = Convert.ToInt32(R * Math.Sin(lat) * Math.Cos(lon));
    XYZ.Z = Convert.ToInt32(R * Math.Sin(lat));
    return XYZ;
}

When plotting these on a graph, I have found that the Y axis varies quite significantly, even though these points are very close to each other, I assume this is due to the fact we are sat on a sphere and unless I was at the north pole, it would be considered slanted, more so the closer to the equator I was. (If this is not the case please do let me know)

Please see the below three points plotted in a 3D scatter graph

enter image description here

Point A would be considered the "central" point where the user is

Point B is a point directly to the south of the user

Point C is a point directly to the north of the user

What I hope to achieve is to rotate points B and C around point A, so that their Y values are the same and I can consider the graph a 2D representation of the points, I found by just changing the Y to the same I ended up with a fairly skewed version of the points.

The end goal is to use the heading of the user and find out if any of the points are within their field of view (for augmented reality)

Any assistance, helpful critique or links to useful articles would be greatly appreciated.

Aphire
  • 1,621
  • 25
  • 55
  • 1
    Can you clarify the last sentence as to what help you were looking for? – EJoshuaS - Stand with Ukraine Sep 08 '17 at 14:33
  • [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix) – J... Sep 08 '17 at 14:35
  • Preferably a commented C# implementation making use of a matrix multiplication, explaining what information is added where and why. As far as I understand it, this is not considered a "basic" rotation as it's not directly around an axis, it's around an arbitrary point, I may very well be wrong however – Aphire Sep 08 '17 at 14:39
  • I know thats a lot to ask, so even just a link to a very "my first matrix" tutorial that would be great to get me along the right path. Or even telling me if I am taking the wrong approach to get the outcome – Aphire Sep 08 '17 at 14:40
  • 1. see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) 2. your conversion is only spherical in case you are **WGS84** it is wrong and will not correspond with **GPS** geo coordinates. To remedy it see last edit in [How to convert a spherical velocity coordinates into cartesian](https://stackoverflow.com/a/41161714/2521214). 3. to rotate you just create transform matrix which translates center of rotation to `(0,0,0)` then rotate and lastly translate back .... to obtain the angles use `atan2` ... – Spektre Sep 08 '17 at 15:16
  • Hmm, why do you want the *Y*-coordinates to match in particular? I don't see how that would help you achieve your end goal. Also that formula for conversion to Cartesian coordinates is wrong. – meowgoesthedog Sep 08 '17 at 16:51

1 Answers1

0

You got wrong equation (did not spot it before :) either) it should be:

public CartesianXYZ LonLat2Cartesian(double lon, double lat)
    {
    CartesianXYZ XYZ = new CartesianXYZ();
    var R = 6371000;
    XYZ.X = Convert.ToInt32(R * Math.Cos(lat) * Math.Cos(lon));
    XYZ.Y = Convert.ToInt32(R * Math.Cos(lat) * Math.Sin(lon));
    XYZ.Z = Convert.ToInt32(R * Math.Sin(lat));
    return XYZ;
    }

btw this is just sphere which our planet is not so if you need more precise result use WGS84:

Spektre
  • 49,595
  • 11
  • 110
  • 380