角度的三维矢量-得到两者
Angles of 3D vector - getting both
本文关键字:三维 更新时间:2023-10-16
我有一个物体A,有一个速度。速度被指定为三维矢量a = (x, y, z)
。位置为三维点A [X, Y, Z]
。我需要弄清楚,当前的速度是否会把这个物体带到位置B [X, Y, Z]
的另一个物体B。
我已经成功地在两个维度中实现了这一点,忽略了第三个维度:
/*A is projectile, B is static object*/
//entity is object A
// - .v[3] is the speed vector
//position[3] is array of coordinates of object B
double vector[3]; //This is the vector c = A-B
this->entityVector(-1, entity.id, vector); //Fills the correct data
double distance = vector_size(vector); //This is distance |AB|
double speed = vector_size(entity.v); //This is size of speed vector a
float dist_angle = (float)atan2(vector[2],vector[0])*(180.0/M_PI); //Get angle of vector c as seen from Y axis - using X, Z
float speed_angle = (float)atan2((double)entity.v[2],entity.v[0])*(180.0/M_PI); //Get angle of vector a seen from Y axis - using X, Z
dist_angle = deg180to360(dist_angle); //Converts value to 0-360
speed_angle = deg180to360(speed_angle); //Converts value to 0-360
int diff = abs((int)compare_degrees(dist_angle, speed_angle)); //Returns the difference of vectors direction
我需要创建非常相同的比较,使其在3D中工作-现在,Y位置和Y向量坐标被忽略。
我应该做什么计算来得到第二个角度?
根据答案编辑
我用球坐标比较它们的角度来检查两个向量是否指向相同的方向。一个矢量是A- b,另一个矢量是A的速度,我要检查A是否朝着b前进
我假设你正在寻找的"第二个角度"是φ。也就是说,你在使用球坐标:
(x,y,z) => (r,θ,φ)
r = sqrt(x^2 + y^2 + z^2)
θ = cos^-1(z/r)
φ = tan^-1(y/x)
然而,如果你想做的只是找出A是否以速度A向B移动,你可以使用点积作为基本答案。
1st vector: B - A (vector pointing from A to B)
2nd vector: a (velocity)
dot product: a * (B-A)
如果点积为0,这意味着你没有靠近——你在一个半径恒定的球体上运动,而B在圆心。如果点积> 0,就向这个点移动,如果点积<0,你在远离它。
相关文章:
- 如何将三维尺寸不固定的三维阵列展平为一维阵列
- 如何使用qt缩放三维网格
- 三维数组中的C/C++DWORD到BYTE和BYTE到DWORD的转换
- 使用vtkImageReslice重新切片三维原始图像
- 特征:创建一个具有函数的三维阵列
- 扩充矩阵的行缩减-三维样条曲线计算
- 使用pcl transformcloud将三维点平移并旋转到原点
- 用C++从三维矢量中删除元素
- 如何访问CGAL三维三角测量中的面
- 如何在Openscenegraph中从二维鼠标点击的屏幕坐标点计算三维点(世界坐标)
- std::将三维数组复制到三维向量中
- 显示结构的三维数组
- 如何将X 2维数组连接到一个三维阵列中
- 使用unique_ptr来管理三维数组
- 如何访问三维矩阵元素
- 无法访问三维数组中的特定位置
- 如何将 HDC 位图快速复制到三维阵列?
- 内存相关崩溃:Cocos2d游戏中的三维数组
- 如何使用opencv和c++实现三维sift算法
- 如何根据给定Z值的图片计算三维坐标