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 35 ThreeD.createCurve = function (board, parents, attr) { 36 var view = parents[0], 37 D3, el; 38 39 D3 = { 40 elType: 'curve3D', 41 X: parents[1], 42 Y: parents[2], 43 Z: parents[3], 44 }; 45 D3.F = [D3.X, D3.Y, D3.Z]; 46 47 el = board.create('curve', [[], []], attr); 48 el.D3 = D3; 49 50 if (Type.isFunction(el.D3.X)) { 51 // 3D curve given as t -> [X(t), Y(t), Z(t)] 52 53 el.D3.range = parents[4]; 54 el.updateDataArray = function () { 55 var steps = Type.evaluate(this.visProp.numberpointshigh), 56 s = Type.evaluate(this.D3.range[0]), 57 e = Type.evaluate(this.D3.range[1]), 58 delta = (e - s) / (steps - 1), 59 c2d, t, i, 60 p = [0, 0, 0]; 61 62 this.dataX = []; 63 this.dataY = []; 64 65 for (t = s; t <= e; t += delta) { 66 for (i = 0; i < 3; i++) { 67 p[i] = this.D3.F[i](t); 68 } 69 c2d = view.project3DTo2D(p); 70 this.dataX.push(c2d[1]); 71 this.dataY.push(c2d[2]); 72 } 73 }; 74 } else if (Type.isArray(el.D3.X)) { 75 // 3D curve given as array of 3D points 76 77 el.updateDataArray = function () { 78 var i, 79 le = this.D3.X.length, 80 c2d; 81 82 this.dataX = []; 83 this.dataY = []; 84 85 for (i = 0; i < le; i++) { 86 c2d = view.project3DTo2D([this.D3.X[i], this.D3.Y[i], this.D3.Z[i]]); 87 this.dataX.push(c2d[1]); 88 this.dataY.push(c2d[2]); 89 } 90 }; 91 } 92 93 return el; 94 }; 95 JXG.registerElement('curve3d', ThreeD.createCurve); 96 97 });