Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Approximate the whole thing to be a sphere and apply the following formula multiplied divided by pixel-to-model-unit ratio. You can calculate the pixel-to-model-unit ratio by rendering a unit sphere at known z coordinate. Good thing about a sphere is that its width is always going to be diameter regardless of where you look from. See <a href="http://en.wikipedia.org/wiki/3D_projection#Perspective_projection" rel="nofollow noreferrer">perspective projection</a> for details.</p> <p><img src="https://upload.wikimedia.org/math/b/0/a/b0a6e114c9ef0dc4e2e4181534f54cb1.png" alt="alt text"></p> <p><strong>Edit</strong>: The good thing about sphere is that it's independent from directions. Regardless of box or sphere you need to specify the direction of camera vector and the <em>up</em> vector. Once you have that, the only unknown is the depth z from the eye's point of view. From there you can calculate the position of the eye by:</p> <pre><code> eye := (center.x, center.y, center.z) - depth * (camera.x, camera.y, camera.z) </code></pre> <p>From the formula, <code>Bx := Ax * Bz / Az</code> You can derive <code>Bz := Bx * Az / Ax</code>. </p> <p>Let me define a model coordinate 1.0 to be 1.0m. Suppose sphere of radius 1.0m from distance 100.0m looks 20 pixels wide.</p> <pre><code>Bz := 1.0 * 100.0 / 10 Bz := 10.0 </code></pre> <p>Now let's say your bounding box is 200.0m wide, which makes Ax to be 100.0, and your screen width is 1024pixel, which makes Bx 512pixel.</p> <pre><code>Az := (Ax / Bx) * Bz Az := (100.0/512.0) * 10.0 Az := 1.953m </code></pre> <p>In the above the unit conversion betwen m and pixel is being absorbed by Bz.</p> <p>Suppose the up vector is (0, 0, 1), camera vector is (1, 0, 0), and the center is (0, 0, 0).</p> <pre><code>eye := center - depth * camera eye := (0, 0, 0) - 1.953 * (1, 0, 0) eye := (-1.953, 0, 0) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload