# Constant orientation of graphics in Graphics3D

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]]

• There are ? Have you written any code you can share with us ? – Sektor Apr 15 '15 at 20:14
• The suboption "RotationControl" to the option Method of Graphics3D 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. – Jinxed Apr 16 '15 at 6:46
• Does this help? – Szabolcs Apr 17 '15 at 16:55

## 1 Answer

Input your line through the origin as myVec:

myVec = {-2, 3, 1};
Graphics3D[{
Rotate[Cuboid[{-.5, -.5, -.5}],
Dynamic[MousePosition[][[1]]/10], {-2, 3, 1}],
Line[{myVec, -myVec}]}]


or...

myVec = {-2, 3, 1};
Graphics3D[{
Rotate[PolyhedronData["Icosahedron", "Faces"],
Dynamic[MousePosition[][[1]]/10], myVec],
Line[{myVec, -myVec}]}]

• David, Thanks for your quick answer. Unfortunately, this does not completely address my problem. With "rotating the cuboid with the mouse" I mean the rotation you can execute when moving with the cursor over the image (click and move mouse). Then, when the cuboid can rotate, the line should be fixed at a constant orientation compared to the view point (which changes during rotation). – florian Apr 15 '15 at 20:24
• @florian Try my new solution. – David G. Stork Apr 15 '15 at 20:37