Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:46+00:00 2026-06-18T03:50:46+00:00

Using three.js I have the following. A scene containing several Object3D instances Several predefined

  • 0

Using three.js I have the following.

  • A scene containing several Object3D instances
  • Several predefined camera Vector3 positions
  • A dynamic width/height of the canvas if the screen resizes
  • A user can select an object (from above)
  • A user can select a camera position (from above)

Given an object being viewed and the camera position they have chosen how do I compute the final camera position to “best fit” the object on screen?

If the camera positions are used “as is” on some screens the objects bleed over the edge of my viewport whilst others they appear smaller. I believe it is possible to fit the object to the camera frustum but haven’t been able to find anything suitable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:50:47+00:00Added an answer on June 18, 2026 at 3:50 am

    I am assuming you are using a perspective camera.

    You can set the camera’s position, field-of-view, or both.

    The following calculation is exact for an object that is a cube, so think in terms of the object’s bounding box, aligned to face the camera.

    If the camera is centered and viewing the cube head-on, define

    dist = distance from the camera to the _closest face_ of the cube
    

    and

    height = height of the cube.
    

    If you set the camera field-of-view as follows

    fov = 2 * Math.atan( height / ( 2 * dist ) ) * ( 180 / Math.PI ); // in degrees
    

    then the cube height will match the visible height.

    At this point, you can back the camera up a bit, or increase the field-of-view a bit.

    If the field-of-view is fixed, then use the above equation to solve for the distance.


    EDIT: If you want the cube width to match the visible width, let aspect be the aspect ratio of the canvas ( canvas width divided by canvas height ), and set the camera field-of-view like so

    fov = 2 * Math.atan( ( width / aspect ) / ( 2 * dist ) ) * ( 180 / Math.PI ); // in degrees
    

    three.js r.69

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following animation set up using Three.js: http://frontier.lincoln.ac.uk/3d/development/Stage2/characters/man2.html Please ignore the ropey
I have the following three files in the same directory: citysim.cpp #include utils.h using
I have the following Scenario: Three different Sharepoint Server: sp1.company.com; sp2.company.com... Internal Users using
I have been following along this example to load .obj Model using three.js. Since
I have to build a tree using the following data which comes from a
I have three textareas using tinymce as text area. They all work in chrome
I have three classes that I am using and have shortened for ease of
I'm using MySQL I have three tables: accounts { account_id, username } account_ips {
I have three tables. I have to retrieve the data using Linq statement. My
I am using jquery UI tabs I have three ajax tabs like so: <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.