2
$\begingroup$

I have s set 3d data points which I want to rotate, so that the size of the box does not change. Also if possible the window size which contains the plot should not change ist size.

How can I achieve that?

Here is my code:

SeedRandom[1];
data = RandomReal[10, {500, 3}];

Manipulate[
  Graphics3D[
    {PointSize[Medium], Point[data, VertexColors -> (Hue /@ Rescale[data[[All, 1]]])]}, 
    SphericalRegion -> True, Axes -> True, 
    AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
    ViewProjection -> "Orthographic", Boxed -> True, 
    AxesLabel -> {"x axis", "y axis", "z axis"}, 
    ViewPoint -> 
      N @ Dynamic[15*{Sin[α] Cos[β], Sin[α] Sin[β], Cos[α]}], ImageSize -> Small], 
  {{α, N @ π/3}, N @ π/360, π, π/360, Appearance -> "Labeled"}, 
  {{β, N@π/4}, 0., 2 π, 2 π/360, Appearance -> "Labeled"}]

Result:

enter image description here

$\endgroup$
5
  • 3
    $\begingroup$ Use clear values ImageSize -> {600, 400} instead of Small. $\endgroup$
    – Kuba
    Commented Dec 13, 2017 at 13:04
  • 3
    $\begingroup$ And explicit ImagePadding, like ImagePadding -> {{10, 10}, {10, 10}}. $\endgroup$ Commented Dec 13, 2017 at 14:03
  • 2
    $\begingroup$ Also SphericalRegion -> True helps to avoid the view point depending shifting of the box. $\endgroup$ Commented Dec 14, 2017 at 13:06
  • 2
    $\begingroup$ @Thies SphericalRegion was also my first reaction, but then realized that it was already included among the options. $\endgroup$ Commented Dec 14, 2017 at 13:53
  • $\begingroup$ @IstvánZachar I see, cool! Didn't notice that. It might still be useful to be aware the parameter exists as a reference for future visitors :) $\endgroup$ Commented Dec 14, 2017 at 15:36

1 Answer 1

1
$\begingroup$

Use ContentSize and Aligment, along with SphericalRegion:

Manipulate[
Graphics3D[{PointSize[Medium], 
Point[data, VertexColors -> (Hue /@ Rescale[data[[All, 1]]])]}, 
SphericalRegion -> True, Axes -> True, 
AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
ViewProjection -> "Ortographic", Boxed -> True, 
AxesLabel -> {"x axis", "y axis", "z axis"}, 
ViewPoint -> 
N@Dynamic[
 50*{Sin[\[Alpha]] Cos[\[Beta]], Sin[\[Alpha]] Sin[\[Beta]], 
   Cos[\[Alpha]]}]
],
{{\[Alpha], N@\[Pi]/3}, N@\[Pi]/360, \[Pi], \[Pi]/360, 
Appearance -> "Labeled"}, {{\[Beta], N@\[Pi]/4}, 0., 2 \[Pi], 
2 \[Pi]/360, Appearance -> "Labeled"},
Alignment -> Center,
ContentSize -> {400, 400},
Initialization :> (SeedRandom[1]; data = RandomReal[10, {500, 3}];)
]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you for the solution. This works also for e.g. data = Transpose[{RandomReal[10, {500}], RandomReal[5, {500}], RandomReal[2, {500}]}]. $\endgroup$
    – mrz
    Commented Dec 15, 2017 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.