From 37b0c870f371685be673d22d5d6c1526144b4c49 Mon Sep 17 00:00:00 2001 From: paulmasson Date: Thu, 11 Jun 2020 17:19:54 -0700 Subject: [PATCH] Update viewpoint option --- src/doc/en/reference/plot3d/threejs.rst | 2 +- src/sage/ext_data/threejs/threejs_template.html | 6 +++--- src/sage/plot/plot3d/base.pyx | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/doc/en/reference/plot3d/threejs.rst b/src/doc/en/reference/plot3d/threejs.rst index 377575e74a4..fe67f6b5b71 100644 --- a/src/doc/en/reference/plot3d/threejs.rst +++ b/src/doc/en/reference/plot3d/threejs.rst @@ -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 diff --git a/src/sage/ext_data/threejs/threejs_template.html b/src/sage/ext_data/threejs/threejs_template.html index 1e926bad329..37043b112a4 100644 --- a/src/sage/ext_data/threejs/threejs_template.html +++ b/src/sage/ext_data/threejs/threejs_template.html @@ -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() ); diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 73444ad6688..ed1e9d73869 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -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