I have been facing a challenge for programming for quite a while now, and I think it is now time for me to consult some Mathematica experts:
I would like to draw a three-dimensional graphic, e.g. cuboid, centered at the origin, together with a line:
Graphics3D[{
Cuboid[{-0.5, -0.5, -0.5}, {0.5, 0.5, 0.5}],
Line[{{0, 0, 0}, {1, 0, 0}}]
}]
Now, when rotating the cuboid with the mouse, I would like to keep the line being oriented in the same direction as at the initial view point. In other words, I want to have the rotation of the line being disabled (i.e. keeping the same constant orientation compared to the changing view point). Are there any easy ways to solve this problem?
Here are my thoughts about the code so far:
v1 = {1.3, -2.4, 2}; (*initial view point*)
v2 = {1, 0, 0}; (*line/vector that should stay at constant orientation*)
vp = Options[Graphics3D, ViewPoint][[1, 2]]; (*dynamic view point*)
Now my idea is to determine the rotation that results when moving the centered cuboid (mouse klick and move) and apply this rotation to my line. Apparantly, this does not seem to work, the line does not stay at a constant position...
Graphics3D[{Cuboid[{-0.5, -0.5, -0.5}, {0.5, 0.5,
0.5}], {Line[{{0,0,0}, Dynamic[RotationTransform[{v1, vp}][v2]]}]}},
ViewPoint -> Dynamic[vp]]
The problem seems to be the rotation. I cannot apply the same rotation as for v1 to v2. If you try the code any replace v2 with v1, v1 stays at a constant position at any view point:
Graphics3D[{Cuboid[{-0.5, -0.5, -0.5}, {0.5, 0.5,
0.5}], {Line[{{0,0,0}, Dynamic[RotationTransform[{v1, vp}][v1]]}]}},
ViewPoint -> Dynamic[vp]]
"RotationControl"
to the optionMethod
ofGraphics3D
might provide a point to start. However, I fail to find more documentation on this than a number of answers here on SE. :( Also, take a look at this specific answer. $\endgroup$