【发布时间】:2019-11-02 18:14:29
【问题描述】:
Example Image here 我正在尝试找到一种方法来计算我的圆柱体顶部圆面上的点。我的情况看起来像这样,我有一个向量,它在 3d 房间中定义我的圆柱体方向。然后我已经用
计算了一个垂直向量Vector3.Cross(vector1, vector2)
现在我使用直径/2 来计算位于圆柱体圆形顶面边缘的点。现在我想将我的向量始终旋转 90 度,以便在曲面边缘获得 4 个点。定义它们的所有 4 个向量都应垂直于圆柱体方向。你能帮我如何旋转第一个垂直线来实现这个吗?
我已经试过了:
Matrix4x4.CreateFromAxisAngle(vectorcylinderdirection, radiant)
然后我再次计算了叉积,但它并没有像我想要的那样工作。
编辑:
public static void calculatePontsOnCylinder()
{
//Calculate Orthogonal Vector to Direction
Vector3 tCylinderDirection = new Vector3(1, 0, 0);
Vector3 tOrthogonal = Vector3.Cross(tCylinderDirection, new Vector3(-tCylinderDirection.Z,tCylinderDirection.X,tCylinderDirection.Y));
Vector3 tNormOrthogonal = Vector3.Normalize(tOrthogonal);
//Calculate point on surface circle of cylinder
//10mm radius
int tRadius = 10;
Vector3 tPointFinder = tNormOrthogonal * tRadius;
//tPointFinder add the cylinder start point
//not yet implemented
//now i need to rotate the vector always 90 degrees to find the 3 other points on the circular top surface of the cylinder
//don't know how to do this
// I thought this should do it
Matrix4x4.CreateFromAxisAngle(tCylinderDirection, (float)DegreeToRadian(90));
}
private static double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
}
在图片中你可以看到一个例子,vector1是我需要的,总是旋转90度,vector2是我的圆柱方向向量
我可能找到了正确的公式:
Vector3 tFinal = Vector3.Multiply((float)Math.Cos(DegreeToRadian(90)), tPointFinder) + Vector3.Multiply((float)Math.Sin(DegreeToRadian(90)), Vector3.Cross(tCylinderDirection, tPointFinder));
Vector3 tFinal180 = Vector3.Multiply((float)Math.Cos(DegreeToRadian(180)), tPointFinder) + Vector3.Multiply((float)Math.Sin(DegreeToRadian(180)), Vector3.Cross(tCylinderDirection, tPointFinder));
Vector3 tFinal270= Vector3.Multiply((float)Math.Cos(DegreeToRadian(270)), tPointFinder) + Vector3.Multiply((float)Math.Sin(DegreeToRadian(270)), Vector3.Cross(tCylinderDirection, tPointFinder));
有趣的是,如果我尝试使用 (1,1,0) 作为圆柱体方向,它会给出正确的方向,但 90 度和 270 度的长度不同。
【问题讨论】:
-
你应该考虑你的坐标系是否是右手的。据我所知.net 不提供这种数学计算,您使用哪个框架进行这些计算?
-
不,它是左手坐标系。到目前为止,我正在使用 System.Numerics。那么有人可以帮助我吗?
-
我可以尝试,但为此您应该发布更多代码,以便我可以重现您的问题。
-
我已经添加了我尝试过的代码,如果你能重现问题那就太好了,事实上应该有像 (0,0,1), (0,-1, 0),(0,1,0),(0,0,-1) 我想。
-
我刚刚在手机上看了看,但我会在我到达我的电脑后尝试一下。乍一看,我认为你可以通过改变你穿过的向量来从圆柱体中得到另外 3 个点(因为你总是考虑旋转 90 度)
标签: c# matrix vector 3d rotation