POV-Ray : Newsgroups : povray.newusers : Calculate the camera position automatic : Re: Calculate the camera position automatic Server Time
30 Jul 2024 20:26:51 EDT (-0400)
  Re: Calculate the camera position automatic  
From: Phil Cook
Date: 9 Sep 2003 07:45:37
Message: <opru8dl5a4eybzwd@news.povray.org>

<fr### [at] computermuseumfh-kielde> wrote:

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

Thanks Florian and Sputnik for the pointers, I slapped myself on the head 
when I looked at the the #declare for TotalX etc., I actually looked up max 
but saw it was for floats and I was thinking in vectors at the time duh!
I actually placed the min_extent at the origin as I have had some strange 
results in scaling objects away from it, as follows:

//POVWin 3.5 file starts here
camera{
location <17,50,-100>
look_at <17,25,0>
}

#declare unitdivider = union{
box{0,<35,52-6,-2.3>}
cylinder{<0,0,0>,<0,0,-2.3>, 6 scale <35/12,1,1> translate <35/2,52-6,0>}
//cylinder{<0,0,0>,<0,0,-2.3>, 6 translate <35/2,52-6,0> scale <35/12,1,1>}
pigment{rgb <1,0,0>} finish{ambient 0.6 diffuse 0.4}
}

object{unitdivider}
//POV file ends here

If I translate then scale as per commented out line, the cylinder floats to 
+x of the box. Shifting the 35/12 to y and z produces the same results in 
the obvious directions.

I've just tried the combined code from you and Florian, and that works fine 
though, of course:).

Am I doing something fundamentally stupid?

--
Phil


-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


Post a reply to this message

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