I'm creating some files in VRML 2.0 programmatically. I need to construct a cylinder which has its bottom at the origin and its top at a given coordinate, but I'm having some problem figuring out the rotation. I have googled it, but the documentation on VRML 2.0 appears to be very scarce.
I assumed that spherical coordinates would work best for what I'm trying to do, so I computed the spherical coordinates (r, theta, phi) for the target point (x,y,z). I then created the file below.
#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
}
}
}
}
}
}
And here is a version with some example values:
#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
}
}
}
}
}
}
If you view this last file, you will see that the cylinder is actually quite close, but not quite there yet.