我正在以編程方式在VRML 2.0中創建一些文件。我需要構造一個圓柱體,它的底部位於原點,頂部位於給定的座標上,但我在計算旋轉時遇到了一些問題。我已經使用了它,但VRML 2.0上的文檔似乎非常稀少。我認爲spherical coordinates最適合我想要做的事情,所以我計算了目標點(x,y,z)的球面座標(r,theta,phi)。然後我創建了下面的文件。如何在原點和VRML中的某些座標之間創建圓柱體
#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
}
}
}
}
}
}
如果您查看此最後一個文件,你會看到,在氣缸實際上是相當接近,但還沒有應用。
不是圓柱節點的默認CENTER就是原點嗎?如果你想讓基地在原點,你需要翻譯它的高度的1/2。此外,圓柱體的高度是根據您希望的頂部位置計算出來的,並且是頂部中間頂部的頂點? http://graphcomp.com/info/specs/sgi/vrml/spec/和http://accad.osu.edu/~pgerstma/class/vnv/resources/info/AnnotatedVrmlRef/Book有一些很好的參考資料。 html – ViennaMike 2015-04-22 16:19:51
圓柱體確實以原點爲中心,但我已經翻譯過了,所以這不是問題。翻譯是邊緣DEF的第七行。頂端的意義確實在中間。我知道第一個參考資料,但對於輪換的具體情況卻非常模糊。第二個參考對我來說是新的,我會看看它。 – user3031033 2015-04-23 06:27:41