# Formula to compute the viewing distance in Lamothes book

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there! I´m reading Lamothe´s book on 3D software rasterization and there´s a formula to compute the viewing distance d on page 547 which is as follows: d = 0.5 * width * tan(theta/2) Although he uses that formula in the book´s samples, I believe it´s not correct and that the right way to compute d would be as follows: d = 0.5 * width / tan(theta/2) For those of you who have read the book, do you mind telling me which one of us is right? Thanks a lot for your help!!

##### Share on other sites
Perhaps I'm misreading the question, but your way sounds correct. Not that I've seen this book.

I assume Width is the width of the view plane, and theta is the field of view of the "camera."

thus, with half of the view triangle, you have a right triangle, with the near angle (being the angle at the camera's position) of theta/2, an adjacent side of D (the distance you're solving for), and an opposite side of width/2 ...

And what with tangent being opposite over adjacent, that'd be W/(2D). Thus

D = 0.5*W/tan(theta/2) = 0.5*W/ (W/2D) = 0.5 * 2*D*W/W = D.

So you sound right to me :)

##### Share on other sites
Drilian, thanks for answering me. Indeed, width is the viewplane´s width an theta is the camera´s field of view. Just like you, I think there´s an error in the book but, as I´ve said, the author uses that formula in the sample programs and they seem to work right.

Anyway, thanks again for answering me.

--Ignacio

##### Share on other sites
What field of view does he use?

If it's 90 degrees (pi/2 radians) in all of the sample programs, then tan(theta/2) = 1, and thus the result would be the same whether he multiplies or divides by that value.

[Edited by - Drilian on March 15, 2005 9:52:01 PM]

##### Share on other sites
Well since the code works for the book, go look at a working example he has and see what formula he uses there :)

##### Share on other sites
The formula is correct (0.5 * width * tan(...) )

remember

x = r cos(theta)
y = r sin(theta)

tan = y/x = sin/cos

What he is doing is multiplying the ratios of the frustum:

0.5 * width * (Y/X)

and extruding it with the width.

[EDIT]
It's sort of confusing to explian why so, we think of it in angles and it's easier that way.

##### Share on other sites
I can't imagine that I'm thinking about this completely backwards.

  width / 2 ____________|           /|          /|         /|        /|       /|      /|     /|ang./|---/|  /| /|/

So, there's my crappy diagram. In it:

It's half of the view frustum, so the angle at the bottom is fov/2.
Since it's HALF the view frustum, the top is width/2.
The length of the line going up the side (the straight one) is length, which is what we're solving for.

Going back to the old SOHCAHTOA dealy from my early math classes (sin = opposite/hypotenuse, cos = adjacent/hypotenuse, and tan=opposite/adjacent), and the fact that "length" is the adjacent side to the angle (theta/2), and "width/2" is the side opposite the angle, that would give us

tan(theta/2) = opposite/adjacent = (width/2)/(length) = width/(2*length)

so, in order to solve for length, you'd need to DIVIDE by the tangent, because

0.5 *width / tan(theta/2) =
0.5 * width / (width/(2*length)) =
0.5 * 2 * width/width * length =
length.

That's my reasoning. If it's wrong, why is it wrong?

##### Share on other sites
Quote:
 Original post by DrilianWhat field of view does he use?If it's 90 degrees (pi/2 radians) in all of the sample programs, then tan(theta/2) = 1, and thus the result would be the same whether he multiplies or divides by that value.

Indeed, he uses a 90 degrees field of view, but I think that the formula is supossed applicable to any angle.

##### Share on other sites
Right...my point was, maybe the formula is wrong, but it works in the programs because it's a 90 degree FOV :)

##### Share on other sites
I told you why but my explanation isn't exactly the right way to explain it.

0.5 * width * tan(theta/2) is THE CORRECT FORMULA.

you have half the width, you understand right?

tan(...) = (Y/X)

When you multiply it by width it extrudes the ratio out to the distance.

• 23
• 10
• 19
• 15
• 14