在知道坐标的情况下找到三维空间中直线的旋转角度

时间:2019-06-19 09:40:31

标签: c# math vector 3d

有一条线,我们知道极点的坐标。 coordinates

我们还可以测量起点和终点之间的距离。

delta_x:  -45.5
delta_y:  59
delta_z:  -4
delta_x1:  -38.5
delta_y1:  40.5
delta_z1:  17

目标是将绿线移到蓝色。第一步,在知道到极点(B和V)的距离的情况下,将点B移动到点V。现在我们需要确定线应相对于点V旋转多少角度,以使其与蓝色点重合。

到点的坐标和距离略有不同,但是请不要注意它。

插图在链接上:

我表示相对于x y z的旋转过程中分层余弦矩阵的旋转角度。但是他们认为不是真正的角度。 我还尝试了其他公式,但它们仅在坐标发生正向变化时起作用。

double rotx1 = -((t[2] * t1[1] - t1[2] * t[1]) / (t1[1] * t1[1] + t1[2] * t1[2]));
double rotx11 = Math.Asin(rotx1) / Math.PI * 180;
double roty1 = -((t[2] * t1[0] - t1[2] * t[0]) / (t1[0] * t1[0] + t1[2] * t1[2]));
double roty11 = Math.Asin(roty1) / Math.PI * 180;
double rotz1 = -((t[1] * t1[0] - t1[1] * t[0]) / (t1[0] * t1[0] + t1[1] * t1[1]));
double rotz11 = Math.Asin(rotz1) / Math.PI * 180;
Console.WriteLine("X=" + Convert.ToString(rotx11) + " Y=" + 
Convert.ToString(roty11) + " Z=" + Convert.ToString(rotz11));

或这个

double[] pos = { 395, -0, 37, 90, 90, 0 };//The coordinates of the first marker.           
double[] pos1 = { 321, -0, 37, 90, 90, 0 };//The coordinates of the second marker.
double[] t = { 0, 0, 0, 0, 0, 0 };
double[] t1 = { 0, 0, 0, 0, 0, 0 };
double[] t2= { 0, 0, 0, 0, 0, 0 };

double x = -45.5;//Known changes in the coordinates of the point of the first marker
double y = 59;
double z = 33 ;

double x1 = -38.5;// Known changes in the coordinates of the point of the second marker
double y1 = 40.5;
double z1 = 54;

t[0] = pos[0] + x;
t[1] = pos[1] + y;
t[2] = pos[2] -4;
t[3] = pos[3];
t[4] = pos[4];
t[5] = pos[5];

t1[0] = pos1[0] + x1;
t1[1] = pos1[1] + y1;
t1[2] = pos1[2] + 17;
t1[3] = pos1[3];
t1[4] = pos1[4];
t1[5] = pos1[5];


double Ayx21 = Math.Atan2(t[1] - t1[1], t[0] - t1[0]) / Math.PI * 180;

double rotx = Math.Atan2(t[1] - t1[1], t[2] - t1[2]);

double roty1111 = -Math.Atan2((t[2] - t1[2]) * Math.Cos(rotx), (t[1] - t1[1]));

double rotz = Math.Atan2(Math.Sin(roty1111), Math.Sin(rotx) * Math.Cos(rotx)) / Math.PI * 180;
double rotx11111 = (rotz) - (Ayx21);
double roty = -Math.Atan2((t[2] - t1[2]) * Math.Cos(rotx), (t[1] - t1[1])) / Math.PI * 180;
t2[0] = pos[0] + x;
t2[1] = pos[1] + y;
t2[2] = pos[2] + z ;//убрать потом -37
t2[3] = (rotx11111);
t2[4] = (90 + roty);

 t2[5] = (180 + rotz);
string position1 = Convert.ToString(t2[0]).Replace(',', '.');
string position2 = Convert.ToString(t2[1]).Replace(',', '.');
string position3 = Convert.ToString(t2[2]).Replace(',', '.');
string angle1 = Convert.ToString(t2[3]).Replace(',', '.');
string angle2 = Convert.ToString(t2[4]).Replace(',', '.');
string angle3 = Convert.ToString(t2[5]).Replace(',', '.');
Console.WriteLine("[" + Convert.ToString(position1) + "," + Convert.ToString(position2) + "," + Convert.ToString(position3) + "," + Convert.ToString(angle1) + "," + Convert.ToString(angle2) + "," + Convert.ToString(angle3) + "]");

0 个答案:

没有答案