简体   繁体   English

绕另一点C#旋转3D对象

[英]Rotate 3D object around another point C#

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. 首先,我对粗糙的图纸表示歉意,但我对3D操作并不精通,对矩阵也只有一个非常基本的了解,因此请尽可能清楚地解释一切,并且不要假设我的知识水平。

I am currently gathering longitude and latitude data and converting it into Cartesian X,Y and Z with the following function: 我目前正在收集经度和纬度数据,并将其转换为具有以下功能的笛卡尔X,Y和Z:

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. 当将它们绘制在图形上时,我发现即使这些点彼此非常接近,Y轴的变化也相当大,我认为这是由于我们坐在球体上,除非我位于北方杆,它会被认为是倾斜的,越接近我的赤道。 (If this is not the case please do let me know) (如果不是这种情况,请告诉我)

Please see the below three points plotted in a 3D scatter graph 请查看3D散点图中绘制的以下三点

在此处输入图片说明

Point A would be considered the "central" point where the user is 点A将被视为用户所在的“中心”点

Point B is a point directly to the south of the user B点是用户南边的一个点

Point C is a point directly to the north of the user C点是用户北边的直接点

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. 我希望实现的是将点B和C绕点A旋转,以使它们的Y值相同,并且我可以将图形视为点的2D表示,我发现只需将Y更改为最终的点与这些点的偏斜版本。

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. 任何帮助,有用的批评或有用文章的链接,将不胜感激。

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: 顺便说一下,这只是我们的星球所不知道的球体,因此如果您需要更精确的结果,请使用WGS84:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM