我以编程方式在VRML 2.0中创建一些文件。我需要构造一个圆柱体,其底部位于原点,顶部位于给定的坐标处,但我在计算旋转时遇到了一些问题。我用谷歌搜索过,但VRML 2.0的文档似乎非常缺乏。
我认为spherical coordinates最适合我尝试做的事情,因此我计算了目标点(x,y,z)的球面坐标(r,theta,phi)。然后我创建了下面的文件。
#VRML V2.0 utf8
DEF v1 Transform {
translation 0 0 0
children Shape {
geometry Sphere {radius .5}
}
}
DEF v2 Transform {
translation x y z
children Shape {
geometry Sphere {radius .5}
}
}
DEF edge Transform {
translation 0 0 0
children Transform {
rotation 0 1 0 theta-pi/2
children Transform {
rotation 0 0 1 phi-pi/2
children Transform {
translation 0 r/2 0
children Shape {
geometry Cylinder {
radius .08
height r
}
}
}
}
}
}
这是一个带有一些示例值的版本:
#VRML V2.0 utf8
DEF v1 Transform {
translation 0 0 0
children Shape {
geometry Sphere {radius .5}
}
}
DEF v2 Transform {
translation 4 3 3
children Shape {
geometry Sphere {radius .5}
}
}
DEF edge Transform {
translation 0 0 0
children Transform {
rotation 0 1 0 -0.54041949679
children Transform {
rotation 0 0 1 -0.92729521779
children Transform {
translation 0 2.915475947 0
children Shape {
geometry Cylinder {
radius .08
height 5.830951895
}
}
}
}
}
}
如果您查看最后一个文件,您会看到圆柱实际上非常接近,但还没有完全接近。
答案 0 :(得分:1)
O.K。,很长一段时间以来我做过这些事情,但我想我知道你的方法不起作用以及如何做到这一点。正如您所尝试的那样,使用球面坐标计算来自FIXED参考框架,该参考框架本身不会旋转。但是一旦你在VRML中的代码中围绕y旋转,z轴就不再指向原来的位置,而是旋转。您的参考框架已更改。
现在一种方法是使用欧拉角和多个x,y和z旋转,但是一旦找出quaternion(代表x,y和y),你应该能够进行一次旋转。 z旋转矢量的坐标和旋转量)。有关公式的来源,请参阅this Q&A。
方法: 您希望圆柱体坐标系中的重定向y轴与从原点到给定坐标的矢量对齐,因此您需要旋转将点0,r,0移动到新指定的x,y,z。这是如何做到的: