3
$\begingroup$

In the documentation about ViewPoint in the section "Properties & Relations" we can read: enter image description here

"Convert ViewPoint to ViewVector by multiplying the length and pointing the center:"

But the images are not exactly same, the first is bigger than second at first glance.

So is it a bug or do they themselves do not know how to convert ViewPoint and ViewCenter to ViewVector?

The code from the documentation page:

Graphics3D[{Sphere[], Cuboid[]}, ViewPoint -> {3, -3, 3}]
Graphics3D[{Sphere[], Cuboid[]}, 
 ViewVector -> {2 {3, -3, 3}, {0, 0, 0}}]
$\endgroup$
6
  • $\begingroup$ I think the difference is only in the ImageSize. Check with AbsoluteOptions (in V13), and you will see that in the second case, the ImageSize is slightly different. If you make it the same in both cases, you will get identical images: Graphics3D[{Sphere[], Cuboid[]}, ViewVector -> {2 {3, -3, 3}, {0, 0, 0}}, ImageSize -> {360, 360}]; Graphics3D[{Sphere[], Cuboid[]}, ViewPoint -> {3, -3, 3}, ImageSize -> {360, 360}]; $\endgroup$
    – Domen
    Commented Sep 15, 2022 at 13:49
  • $\begingroup$ No, they are not same, they may look like same, but try to rasterize both and compare image data. They are not equal. $\endgroup$ Commented Sep 15, 2022 at 13:56
  • $\begingroup$ Ah, well, you are partly right. I was displaying them in a row, Row[{Graphics3D[...], Graphics3D[]}], in which case they are the same. Displayed separately, they are indeed not. Still, it looks like there is something about the margins/paddings, because they are not fundamentaly different (perspective-wise), only rescaled. $\endgroup$
    – Domen
    Commented Sep 15, 2022 at 14:09
  • $\begingroup$ We are using mathematical tool not artistic. I want exact matching pixel by pixel. What is the exact mathematical formula for relation between Viewpoint, ViewCentrer and ViewVector? What they claim about their relation in the documentation is incorrect. If it was correct the images must have been the same regarding comparing their image data. $\endgroup$ Commented Sep 15, 2022 at 14:17
  • $\begingroup$ Strongly related, if not duplicates: (1), (2). $\endgroup$ Commented Sep 15, 2022 at 14:31

1 Answer 1

4
$\begingroup$

As I have already suspected in the comments, there does not seem to be a problem in the formula for conversion between ViewPoint and ViewVector because the output images are only scaled versions of one another, and the difference is only in the outer padding.

The problematic option seems to be SphericalRegion, which is set to Automatic by default. Apparently, using ViewPoint turns SphericalRegion to False, making the output graphics be cropped to the top and bottom edge.

Let's first omit specifying SphericalRegion. To make the output images of same size, ImageSize has to be set manually.

Quit[];
ClearSystemCache[];

$Version
(* "12.3.1 for Microsoft Windows (64-bit) (June 24, 2021)" *)

a = Graphics3D[{Sphere[], Cuboid[]}, ViewVector -> {2 {3, -3, 3}, {0, 0, 0}}, 
   ImageSize -> {300, 300}];
b = Graphics3D[{Sphere[], Cuboid[]}, ViewPoint -> {3, -3, 3}, 
   ImageSize -> {300, 300}];

imga = Rasterize@a;
imgb = Rasterize@b;

GraphicsRow[{ImageAdjust[imga + imgb], ImageAdjust[imga - imgb]}, ImageSize -> 300]

Different

Now specify SphericalRegion -> True.

Quit[];
ClearSystemCache[];

c = Graphics3D[{Sphere[], Cuboid[]}, ViewVector -> {2 {3, -3, 3}, {0, 0, 0}}, 
   SphericalRegion -> True];
d = Graphics3D[{Sphere[], Cuboid[]}, ViewPoint -> {3, -3, 3}, 
   SphericalRegion -> True];

imgc = Rasterize@c;
imgd = Rasterize@d;

GraphicsRow[{ImageAdjust[imgc + imgd], ImageAdjust[imgc - imgd]}, ImageSize -> 300]

MinMax[imgc - imgd]
(* {-0.501961, 0.376471} *)

Same

Both results now match. Although they are indeed not pixel-perfectly matching, I would consider this to be the solution for your problem. The remaining differences are probably – in my opinion – due to small numerical "errors" in the underlying linear algebra for graphics (when using either ViewPoint or ViewVector), and subsequent rasterization.

Note: I get the very similar results also in "13.0.0 for Microsoft Windows (64-bit) (December 3, 2021)".

$\endgroup$
2
  • $\begingroup$ But this just means that when ViewPoint and ViewCenter are used the algorithm to render output is different than algorithm used with ViewVector. If the algorithm was the same and inputs given with same precision there can not be any differences (the conversion between the two is just one multiplication and sometimes even without it when box width is 1). Then it has no much sense to explain how to convert between those two parameters if they do not state that it is just approximation - the more it is mathematical tool. $\endgroup$ Commented Sep 15, 2022 at 16:48
  • $\begingroup$ I accept your answer but not because it would solve my problem. I consider it to be a bug and so there could not be any better answer. $\endgroup$ Commented Sep 15, 2022 at 16:59

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.