Skip to content

Commit

Permalink
gh-pr-34960: Improve camera positioning for threejs
Browse files Browse the repository at this point in the history
    
Fixes #34822.

The template says that we are not yet accepting PRs. But I will just go
ahead.
    
URL: #34960
Reported by: Kwankyu Lee
Reviewer(s): Dima Pasechnik
  • Loading branch information
Release Manager committed Feb 19, 2023
2 parents 9773108 + 952a6c9 commit 8e038e1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/sage/ext_data/threejs/threejs_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,17 @@
camera.up.set( 0, 0, 1 );
camera.position.set( a[0]*xMid, a[1]*yMid, a[2]*zMid );

var offset = new THREE.Vector3( a[0]*xRange, a[1]*yRange, a[2]*zRange );
// camera is positioned so that the line from the camera to the center
// of the bounding sphere of the objects makes an angle of 60 degrees with x-axis
// and an angle of 30 degrees with z-axis and the field of view of the camera looking
// at the center has an angle of 45 degrees.
const sin8 = Math.sin(Math.PI / 8);
const sin5 = Math.sin(Math.PI / 5);
const cos5 = Math.cos(Math.PI / 5);
const sin3 = Math.sin(Math.PI / 3);
const cos3 = Math.cos(Math.PI / 3);
var r = midToCorner / sin8;
var offset = new THREE.Vector3( r * sin3 * cos5, r * sin3 * sin5, r * cos3 );

if ( options.viewpoint ) {

Expand Down Expand Up @@ -569,7 +579,7 @@
setTimeout( function() { m.style.display = 'none'; }, 2000 );

}

</script>

<div id="menu-container" onclick="toggleMenu()">&#x24d8;
Expand Down

0 comments on commit 8e038e1

Please sign in to comment.