POV-Ray : Newsgroups : povray.newusers : Calculate the camera position automatic : Re: Calculate the camera position automatic Server Time
4 Nov 2024 13:01:50 EST (-0500)
  Re: Calculate the camera position automatic  
From:
Date: 8 Sep 2003 19:24:01
Message: <3f5d0f91$1@news.povray.org>
Hi Phil and Florian!

Because the camera's look-at is <.5,.5,.5>, a box{0,1} is exactly what
is needed, but unfortunately Phil's calculations are a bit wrong: they
only work if Minimum.x and Maximum.x have different sign or one of them
is zero. (Similar for .y, .z.) The correct formulas are

  #declare TotalX = Maximum.x-Minimum.x;
  #declare TotalY = Maximum.y-Minimum.y;
  #declare TotalZ = Maximum.z-Minimum.z;

abs is not required.
The calculation of MaxLength can be simplified to

  #declare MaxLength = max(TotalX,TotalY,TotalZ);

or, compressing all this into one statement:

  #declare MaxLength = max(
    Maximum.x-Minimum.x,
    Maximum.y-Minimum.y,
    Maximum.z-Minimum.z );


The vector <-Minimum.x,-Minimum.y,-Minimum.z> is the same as -Minimum,
so positioning of the Object is done by

  object { Object translate -Minimum scale 1/MaxLength }


The spheres for indication of the bounds are more easily readable as

union {
  sphere{<0,0,0>,0.1}
  sphere{<1,0,0>,0.1}
  sphere{<0,1,0>,0.1}
  sphere{<0,0,1>,0.1}
  sphere{<1,1,0>,0.1}
  sphere{<1,0,1>,0.1}
  sphere{<0,1,1>,0.1}
  sphere{<1,1,1>,0.1}
  pigment {rgbt <0,1,0,0.5>} finish{ambient 0.4 diffuse 0.6}
  }


So, aside from the errors with TotalX/Y/Z, Phil's code is correct.
But I agree with Florian that a box{-0.5,0.5} might be better because
the look_at would be 0 in this case which makes the placement of the
camera a bit easier: I prefer to define the position of the camera by
rotation (instead of absolute coordinates), which is easier with a
look_at of 0. For example:

  camera { location -Distance*z look_at 0 rotate <Elevation,Rotation,0> }

Distance should be chosen in such a way that all points of the Object are
visible for arbitrary values of Elevation and Rotation. The maximum
distance from the origin of a point in a box{-0.5,0.5} is sqrt(3*0.5^2)
=sqrt(0.75). All the points with this distance from the origin lie on a
sphere{0,sqrt(0.75)}. If this sphere is completely visible, then the
Object also is completely visible regardless of rotations of the camera.
A bit of calculation reveals a neccessary Distance of sqrt(3.75)=1.9365
(or more, for example 2) for a standard camera.

   Sputnik


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.