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

Commit

Permalink
Update viewpoint option
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmasson committed Jun 12, 2020
1 parent 66d3471 commit 37b0c87
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/doc/en/reference/plot3d/threejs.rst
Expand Up @@ -59,7 +59,7 @@ 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
- ``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
Expand Down
6 changes: 3 additions & 3 deletions src/sage/ext_data/threejs/threejs_template.html
Expand Up @@ -152,9 +152,9 @@

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 aa = options.viewpoint;
var axis = new THREE.Vector3( aa[0][0], aa[0][1], aa[0][2] ).normalize();
var angle = aa[1] * Math.PI / 180;
var q = new THREE.Quaternion().setFromAxisAngle( axis, angle ).inverse();

offset.set( 0, 0, offset.length() );
Expand Down
9 changes: 9 additions & 0 deletions src/sage/plot/plot3d/base.pyx
Expand Up @@ -385,6 +385,15 @@ cdef class Graphics3d(SageObject):
js_options['aspectRatio'] = [float(i) for i in js_options['aspectRatio']]
js_options['decimals'] = int(js_options['decimals'])

if js_options['viewpoint']:
import warnings
if len(js_options['viewpoint']) != 2 or len(js_options['viewpoint'][0]) != 3:
warnings.warn('viewpoint must be of the form [[x,y,z],angle]')
js_options['viewpoint'] = False
else:
js_options['viewpoint'][0] = [float(i) for i in js_options['viewpoint'][0]]
js_options['viewpoint'][1] = float(js_options['viewpoint'][1])

if not js_options['frame']:
js_options['axesLabels'] = False

Expand Down

0 comments on commit 37b0c87

Please sign in to comment.