File indexing completed on 2024-05-05 03:41:16
0001 /************************************************************************************* 0002 * Copyright (C) 2010-2012 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #include "private/abstractspacecurve.h" 0020 #include "private/functiongraphfactory.h" 0021 0022 #include <analitza/value.h> 0023 #include <analitza/vector.h> 0024 0025 using namespace Analitza; 0026 0027 class ParametricCurve3D : public AbstractSpaceCurve 0028 { 0029 public: 0030 CONSTRUCTORS(ParametricCurve3D) 0031 TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Parametric Curve 3D")) 0032 EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter( 0033 Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter( 0034 Analitza::ExpressionType(Analitza::ExpressionType::Vector, 0035 Analitza::ExpressionType(Analitza::ExpressionType::Value), 3))) 0036 COORDDINATE_SYSTEM(Cartesian) 0037 PARAMETERS(QStringList(QStringLiteral("t"))) 0038 ICON_NAME(QStringLiteral("newparametric3d")) 0039 EXAMPLES(QStringList(QStringLiteral("t->vector {t,t**2,t}"))) 0040 0041 void update(const QVector3D & oppositecorner1, const QVector3D & oppositecorner2) override; 0042 0043 private: 0044 int resolution() { return 5000; } 0045 Cn findTValueForPoint(const QPointF& p); 0046 }; 0047 0048 void ParametricCurve3D::update(const QVector3D & /*oppositecorner1*/, const QVector3D & /*oppositecorner2*/) 0049 { 0050 QPair< double, double > theInterval; 0051 if(hasIntervals()) 0052 theInterval = interval(QStringLiteral("t")); 0053 else 0054 theInterval = qMakePair(-3.1415*5, 3.1415*5); 0055 double dlimit=theInterval.first; 0056 double ulimit=theInterval.second; 0057 0058 points.clear(); 0059 jumps.clear(); 0060 points.reserve(resolution()); 0061 0062 double inv_res = double((ulimit-dlimit)/resolution()); 0063 0064 QVector3D curp; 0065 0066 arg(QStringLiteral("t"))->setValue(dlimit); 0067 Expression res; 0068 0069 for(double t=dlimit; t<ulimit; t+=inv_res) { 0070 arg(QStringLiteral("t"))->setValue(t); 0071 res=analyzer->calculateLambda(); 0072 0073 Cn x=res.elementAt(0).toReal(); 0074 Cn y=res.elementAt(1).toReal(); 0075 Cn z=res.elementAt(2).toReal(); 0076 0077 curp = QVector3D(x.value(), y.value(), z.value()); 0078 0079 points.append(curp); 0080 } 0081 } 0082 0083 REGISTER_SPACECURVE(ParametricCurve3D)