Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add viewpoint option
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Jun 9, 2020
1 parent 860e4dc commit 66d3471
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/doc/en/reference/plot3d/threejs.rst
Expand Up @@ -59,6 +59,9 @@ Options currently supported by the viewer:

- ``thickness`` -- (default: 1) numeric value for thickness of lines

- ``viewpoint`` -- (default: None) string of the form '[x,y,z],angle' setting the initial viewpoint
of the scene; can be determined using the 'Get Viewpoint' option of the information menu

Clicking on the information icon in the lower right-hand corner of the viewer opens
a menu of available actions. These include saving the three-dimensional scene as a static
PNG image or as complete HTML source code.
Expand Down
18 changes: 17 additions & 1 deletion src/sage/ext_data/threejs/threejs_template.html
Expand Up @@ -146,7 +146,23 @@

var camera = createCamera();
camera.up.set( 0, 0, 1 );
camera.position.set( a[0]*(xMid+xRange), a[1]*(yMid+yRange), a[2]*(zMid+zRange) );
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 );

if ( options.viewpoint ) {

var aa = options.viewpoint.replace('[','').replace(']','').split(',');
var axis = new THREE.Vector3( aa[0], aa[1], aa[2] );
var angle = aa[3] * Math.PI / 180;
var q = new THREE.Quaternion().setFromAxisAngle( axis, angle ).inverse();

offset.set( 0, 0, offset.length() );
offset.applyQuaternion( q );

}

camera.position.add( offset );

function createCamera() {

Expand Down
1 change: 1 addition & 0 deletions src/sage/plot/plot3d/base.pyx
Expand Up @@ -374,6 +374,7 @@ cdef class Graphics3d(SageObject):
js_options['decimals'] = options.get('decimals', 2)
js_options['frame'] = options.get('frame', True)
js_options['projection'] = options.get('projection', 'perspective')
js_options['viewpoint'] = options.get('viewpoint', False)

if js_options['projection'] not in ['perspective', 'orthographic']:
import warnings
Expand Down

0 comments on commit 66d3471

Please sign in to comment.