我正在以编程方式在 VRML 2.0 中创建一些文件。我需要构建一个圆柱体,其底部位于原点,顶部位于给定坐标处,但在计算旋转时遇到了一些问题。我已经用谷歌搜索过了,但关于 VRML 2.0 的文档似乎非常稀缺。
我假设球坐标最适合我想要做的事情,所以我计算了目标点 (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
}
}
}
}
}
}
如果您查看最后一个文件,您会看到圆柱体实际上非常接近,但还没有完全接近。