You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已知坐标求解三维空间中直线绕定点的旋转角度

求解直线绕定点旋转至重合的XYZ轴旋转角度问题

我最近在处理一个三维几何的旋转问题,卡了好一阵,想请教下大家的思路:

已知一条绿色直线(端点坐标变化量为delta_x: -45.5、delta_y: 59、delta_z: -4)和一条蓝色直线(端点坐标变化量为delta_x1: -38.5、delta_y1: 40.5、delta_z1: 17),我已经完成了第一步:把绿色直线的端点B移动到蓝色直线的端点V,现在需要计算绿色直线绕点V旋转的XYZ轴角度,让两条直线完全重合(可以忽略微小的坐标和距离误差)。

我试过的方法和遇到的问题:

  • 尝试用方向余弦矩阵推导旋转角度,但得到的结果并不是真实的旋转角度;
  • 也试过其他公式,但这些公式只适用于坐标正变化的场景,没法适配当前存在负坐标变化的情况。

我写的两段尝试代码(C#):

第一段尝试用正弦值计算角度:

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) + "]");

希望能得到正确的旋转角度计算方法,不管坐标变化是正还是负都能适用,或者帮我修正现有代码的问题,让它能输出正确的XYZ旋转角度,实现两条直线的重合。

内容的提问来源于stack exchange,提问作者Wiii

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:54:52