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是不同的。
示例图像在这里,我试图找到一种方法来计算圆柱体顶圆表面上的点。我的情况看起来像这样,我有一个向量来定义3d房间中的圆柱方向。 ...
这里是满足输入要求的代码,应该可以解决您的问题。