diff --git a/src/doc/en/reference/plot3d/threejs.rst b/src/doc/en/reference/plot3d/threejs.rst index 82ddf609f71..377575e74a4 100644 --- a/src/doc/en/reference/plot3d/threejs.rst +++ b/src/doc/en/reference/plot3d/threejs.rst @@ -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. diff --git a/src/sage/ext_data/threejs/threejs_template.html b/src/sage/ext_data/threejs/threejs_template.html index 5f5715276ab..1e926bad329 100644 --- a/src/sage/ext_data/threejs/threejs_template.html +++ b/src/sage/ext_data/threejs/threejs_template.html @@ -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() { diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 2d53ec23945..73444ad6688 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -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