1 /*
  2     Copyright 2008-2022
  3         Matthias Ehmann,
  4         Carsten Miller,
  5         Andreas Walter,
  6         Alfred Wassermann
  7 
  8     This file is part of JSXGraph.
  9 
 10     JSXGraph is free software dual licensed under the GNU LGPL or MIT License.
 11 
 12     You can redistribute it and/or modify it under the terms of the
 13 
 14       * GNU Lesser General Public License as published by
 15         the Free Software Foundation, either version 3 of the License, or
 16         (at your option) any later version
 17       OR
 18       * MIT License: https://github.com/jsxgraph/jsxgraph/blob/master/LICENSE.MIT
 19 
 20     JSXGraph is distributed in the hope that it will be useful,
 21     but WITHOUT ANY WARRANTY; without even the implied warranty of
 22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 23     GNU Lesser General Public License for more details.
 24 
 25     You should have received a copy of the GNU Lesser General Public License and
 26     the MIT License along with JSXGraph. If not, see <http://www.gnu.org/licenses/>
 27     and <http://opensource.org/licenses/MIT/>.
 28  */
 29 /*global JXG:true, define: true*/
 30 
 31 define(['jxg', 'utils/type', '3d/view3d'
 32 ], function (JXG, Type, ThreeD) {
 33     "use strict";
 34     ThreeD.createParametricSurface = function (board, parents, attributes) {
 35         var view = parents[0],
 36             attr,
 37             X = parents[1],
 38             Y = parents[2],
 39             Z = parents[3],
 40             range_u = parents[4],
 41             range_v = parents[5],
 42             D3, el;
 43 
 44         D3 = {
 45             elType: 'surface3d',
 46             X: X,
 47             Y: Y,
 48             Z: Z,
 49             range_u: range_u,
 50             range_v: range_v
 51         };
 52         attr = Type.copyAttributes(attributes, board.options, 'surface3d');
 53         el = board.create('curve', [[], []], attr);
 54         el.updateDataArray = function () {
 55             var steps_u = Type.evaluate(this.visProp.stepsu),
 56                 steps_v = Type.evaluate(this.visProp.stepsv),
 57                 res = view.getMesh(this.D3.X, this.D3.Y, this.D3.Z,
 58                     this.D3.range_u.concat([steps_u]),
 59                     this.D3.range_v.concat([steps_v]));
 60             this.dataX = res[0];
 61             this.dataY = res[1];
 62         };
 63         el.D3 = D3;
 64 
 65         return el;
 66     };
 67     JXG.registerElement('parametricsurface3d', ThreeD.createParametricSurface);
 68 
 69     ThreeD.createFunctiongraph = function (board, parents, attributes) {
 70         var view = parents[0],
 71             X = function(u, v) { return u; },
 72             Y = function(u, v) { return v; },
 73             Z = parents[1],
 74             range_u = parents[2],
 75             range_v = parents[3];
 76 
 77         return view.create('parametricsurface3d', [X, Y, Z, range_u, range_v], attributes);
 78     };
 79     JXG.registerElement('functiongraph3d', ThreeD.createFunctiongraph);
 80 
 81 });