POV-Ray : Newsgroups : povray.general : How to set the view to the object width? Server Time
31 Oct 2024 19:26:59 EDT (-0400)
  How to set the view to the object width? (Message 1 to 10 of 10)  
From: Kima
Subject: How to set the view to the object width?
Date: 21 Sep 2019 17:35:07
Message: <web.5d86968bd4ff5744ecc0fada0@news.povray.org>
I tried to set the camera location to fix the view to the object width using
this formula

direction_length = 0.5 * right_length / tan(angle / 2) where right_length

as

#declare o1 = sphere { <0,0,0>,1 pigment{color rgb<0,0,1>} finish{phong 1} }
#declare l1 = min_extent(o1);
#declare l2 = max_extent(o1);
#declare lx=0.25*(l2.x-l1.x)/-0.8559934009;

camera {location <0,0,lx> look_at <0,0,0> angle 30}
light_source {<2,5,-5> color rgb<1,1,1>  }

object{o1}

but lx should at least 10 times larger to view the whole object. Where is my
mistake?


Post a reply to this message

From: Bald Eagle
Subject: Re: How to set the view to the object width?
Date: 21 Sep 2019 19:00:00
Message: <web.5d86aa9b756e04084eec112d0@news.povray.org>
I haven't worked out a solution yet, or maybe I have in the past and can't
remember / locate it (yet), but at:

http://news.povray.org/povray.advanced-users/thread/%3C53ff3a80@news.povray.org%3E/

clipka says,

"If you specify a camera angle, it directly specifies the horizontal
field of view; the aspect ratio (relative length of the right and up
vectors, which should ideally fit the image aspect ratio) determines the
vertical field of view."

and

"If you're not using angle, the ratio of the direction vector's length to
that of the right vector's also determines the field of view, ..."

So maybe that helps.


Post a reply to this message

From: Bald Eagle
Subject: Re: How to set the view to the object width?
Date: 21 Sep 2019 20:40:00
Message: <web.5d86c27d756e04084eec112d0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I haven't worked out a solution yet, or maybe I have in the past and can't
> remember / locate it (yet), but at:


I still haven't found what I'm looking for - I could swear that I had written
some code to do this already....


but if you take a look at:

http://news.povray.org/web.591ae6ba4e850994c437ac910%40news.povray.org

I do some calculations to find what radius is always at least 1 pixel wide, and
thus always visible.

If you define that radius to be the image_width, and then work backwards, you
should wind up with a camera position.


I'll see if I can work it out after I get some sleep, but if you're going to
hammer away at this, I always find that a diagram, a spreadsheet, and some good
#debug directives in the code really help me work this kind of thing out lots
faster.

(also, see: http://news.povray.org/58f60d9e%241%40news.povray.org to avoid any
atan problems   ;)   )


Post a reply to this message

From: Kima
Subject: Re: How to set the view to the object width?
Date: 21 Sep 2019 21:35:00
Message: <web.5d86cef3756e0408ecc0fada0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > I haven't worked out a solution yet, or maybe I have in the past and can't
> > remember / locate it (yet), but at:
>
>
> I still haven't found what I'm looking for - I could swear that I had written
> some code to do this already....
>
>
> but if you take a look at:
>
> http://news.povray.org/web.591ae6ba4e850994c437ac910%40news.povray.org
>
> I do some calculations to find what radius is always at least 1 pixel wide, and
> thus always visible.
>
> If you define that radius to be the image_width, and then work backwards, you
> should wind up with a camera position.
>
>
> I'll see if I can work it out after I get some sleep, but if you're going to
> hammer away at this, I always find that a diagram, a spreadsheet, and some good
> #debug directives in the code really help me work this kind of thing out lots
> faster.
>
> (also, see: http://news.povray.org/58f60d9e%241%40news.povray.org to avoid any
> atan problems   ;)   )

First of all, I must correct a stupid mistake (in using the calculator). The
tan(15) = 0.26794919

However, my problem with the above-mentioned equation
(https://www.povray.org/documentation/view/3.6.1/246/) still stands.

To make the equation work, I must omit 0.5, and I don't know where it comes
from.

Simple example:

Consider the angle of view of 90, then, direction_length = right_length. Since
tang(45) = 1, 0.5 is superfulous.

I can think of 0.5 necessary if only using full_length
(left_lenth+right_lenght). Or amd I making another stupid mistake?


Post a reply to this message

From: Bald Eagle
Subject: Re: How to set the view to the object width?
Date: 22 Sep 2019 08:50:00
Message: <web.5d876d50756e04084eec112d0@news.povray.org>
"Kima" <nomail@nomail> wrote:

> To make the equation work, I must omit 0.5, and I don't know where it comes
> from.
>
> Simple example:
>
> Consider the angle of view of 90, then, direction_length = right_length. Since
> tang(45) = 1, 0.5 is superfulous.
>
> I can think of 0.5 necessary if only using full_length
> (left_lenth+right_lenght). Or amd I making another stupid mistake?

I feel your pain.   I've been through this before, and I found the answer, but
it was too long ago for me to remember where the description / diagram /
explanation lies.

_Somewhere_ in the documentation, and probably in a forum thread or two lies a
discussion of how the camera angle is DEFINED.

IIRC, it isn't what you think it might be, but half of that.

My advice to you - for a lot of things - will be to pretend like POV-Ray and the
documentation don't exist, and look up how "standard computer graphics" stuff
works.   In this case, the view frustum and projection matrices.
The diagrams and explanations and equations will be a lot more extensive,
varied, and often clearer.   A lot of it will discussing OpenGL and other
software, but that's irrelevant, since it's all using the same fundamentals.


https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/projection-matr
ices-what-you-need-to-know-first?url=3d-basic-rendering/perspective-and-orthographic-projection-matrix/projection-matri
ces-what-you-need-to-know-first

Take a look at that first diagram, where FOV=90.   It only intuitively
illustrates what I'm trying to recall, but I hope it will establish that it's
not a figment of my imagination or memory.

Perhaps one of the developers can chime in with details or a link.


Post a reply to this message

From: Bald Eagle
Subject: Re: How to set the view to the object width?
Date: 22 Sep 2019 11:55:00
Message: <web.5d879927756e04084eec112d0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> IIRC, it isn't what you think it might be, but half of that

I think maybe this series of equation rearrangements might shed some light on
the issue.

From:
http://news.povray.org/povray.advanced-users/thread/%3Cweb.580f8b048d6e3073b488d9aa0%40news.povray.org%3E/

// direction_length = 0.5 * right_length / tan(angle / 2)
// tan(angle / 2) * direction_length = 0.5 * right_length
// tan(angle / 2) = (0.5 * right_length) / direction_length
// (angle / 2) = atan2( (0.5 * right_length), direction_length)
// angle = 2* atan2( (0.5 * right_length), direction_length)


Post a reply to this message

From: Kima
Subject: Re: How to set the view to the object width?
Date: 22 Sep 2019 13:55:01
Message: <web.5d87b4fc756e0408ecc0fada0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
>
> > IIRC, it isn't what you think it might be, but half of that
>
> I think maybe this series of equation rearrangements might shed some light on
> the issue.
>
> From:
>
http://news.povray.org/povray.advanced-users/thread/%3Cweb.580f8b048d6e3073b488d9aa0%40news.povray.org%3E/
>
> // direction_length = 0.5 * right_length / tan(angle / 2)
> // tan(angle / 2) * direction_length = 0.5 * right_length
> // tan(angle / 2) = (0.5 * right_length) / direction_length
> // (angle / 2) = atan2( (0.5 * right_length), direction_length)
> // angle = 2* atan2( (0.5 * right_length), direction_length)

Thanks for the links and suggestions, they are quite useful.

However, my problem appears in all of the equations you mentioned. The problem
is of trigonometry nature. We have a triangle as depicted here
https://www.povray.org/documentation/view/3.6.1/246/ one side is
direction_length and one side is right_length (half of the view). Tangent
defines their ratio. Where does the "0.5" come from?


Post a reply to this message

From: Bald Eagle
Subject: Re: How to set the view to the object width?
Date: 22 Sep 2019 14:40:01
Message: <web.5d87bf98756e04084eec112d0@news.povray.org>
"Kima" <nomail@nomail> wrote:

> > // angle = 2* atan2( (0.5 * right_length), direction_length)

> one side is
> direction_length and one side is right_length

Which is what?

(half of the view).

And there is the answer.  Because Right is usually a unit vector, but the view
frustum is twice as wide as that.

> Tangent
> defines their ratio. Where does the "0.5" come from?

So you use 0.5*right in your trig to get the _half angle_, and then multiply by
two to get - the full angle.

Don't feel bad.
I go through this EVERY TIME.











I'll just throw a few keywords here to make searching for this post easier in
the future.

Bald Eagle Kima camera angle half_angle full_angle distance_vector right_vector
half_vector


Post a reply to this message

From: Bald Eagle
Subject: Re: How to set the view to the object width?
Date: 22 Sep 2019 19:35:01
Message: <web.5d880451756e04084eec112d0@news.povray.org>
So, I'm working on a scene to illustrate this.

#declare Aspect = image_width/image_height;
#declare Right_Vector = <1, 0, 0>*Aspect;
#declare Screen_Plane = z;
#declare Camera_Loc = <0, 0, 0>;
#declare Screen_Center = <0, 0, 1>;
#declare Right_Vector = <1, 0, 0>*Aspect;     //<---------

#declare direction_length = vlength (Screen_Center - Camera_Loc);

#declare half_angle = degrees(atan2( (0.5 * vlength(Right_Vector)),
direction_length));

This gives 33.69

Multiplying this by two gives the default camera angle of 67.380


Post a reply to this message

From: Bald Eagle
Subject: Re: How to set the view to the object width?
Date: 22 Sep 2019 21:30:00
Message: <web.5d881f4e756e04084eec112d0@news.povray.org>
I made a new diagram:

http://news.povray.org/povray.binaries.images/message/%3Cweb.5d881ea3763463c54eec112d0%40news.povray.org%3E/#%3Cweb.5d8
81ea3763463c54eec112d0%40news.povray.org%3E


Post a reply to this message

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