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/abstractsurface.h" 0020 // #include "private/surfacefactory.h" 0021 #include "private/functiongraphfactory.h" 0022 #include <private/utils/mathutils.h> 0023 0024 #include <analitza/value.h> 0025 #include <analitza/vector.h> 0026 0027 using namespace Analitza; 0028 0029 class SphericalSurface : public AbstractSurface/*, static class? better macros FooClass*/ 0030 { 0031 public: 0032 explicit SphericalSurface(const Analitza::Expression& e); 0033 SphericalSurface(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v); 0034 0035 TYPE_NAME(QT_TRANSLATE_NOOP("Function type", "Spherical Surface Radial=F(t:Azimuth, p: Polar)")) 0036 EXPRESSION_TYPE(Analitza::ExpressionType(Analitza::ExpressionType::Lambda).addParameter( 0037 Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter( 0038 Analitza::ExpressionType(Analitza::ExpressionType::Value)).addParameter( 0039 Analitza::ExpressionType(Analitza::ExpressionType::Value))) 0040 COORDDINATE_SYSTEM(Cartesian) 0041 PARAMETERS(QStringList(QStringLiteral("t"))<< QStringLiteral("p")) // t azimuth p polar 0042 ICON_NAME(QStringLiteral("newspherical")) 0043 EXAMPLES(QStringList()) 0044 0045 //Own 0046 virtual bool setInterval(const QString& argname, const Analitza::Expression& min, const Analitza::Expression& max) override; 0047 virtual bool setInterval(const QString& argname, double min, double max) override; 0048 0049 QVector3D fromParametricArgs(double u, double v) override; 0050 void update(const QVector3D& oppositecorner1, const QVector3D& oppositecorner2) override; 0051 0052 0053 }; 0054 0055 bool SphericalSurface::setInterval(const QString& argname, const Analitza::Expression& min, const Analitza::Expression& max) 0056 { 0057 0058 Analitza::Analyzer *intervalsAnalizer = new Analitza::Analyzer(analyzer->variables()); 0059 0060 QPair<Analitza::Expression, Analitza::Expression> ival = interval(argname, true); 0061 0062 double min_val = ival.first.toReal().value(); 0063 double max_val = ival.second.toReal().value(); 0064 0065 delete intervalsAnalizer; 0066 0067 if (min_val<0 || max_val < 0) // el radio es distancia por tanto es positivo, el angulo va de 0 hasta +inf 0068 return false; 0069 0070 if (argname == QStringLiteral("t") && max_val >= 2*M_PI) 0071 return false; 0072 0073 if (argname == QStringLiteral("p") && max_val > M_PI) 0074 return false; 0075 0076 return AbstractFunctionGraph::setInterval(argname, min, max); 0077 } 0078 0079 bool SphericalSurface::setInterval(const QString& argname, double min, double max) 0080 { 0081 if (min<0 || max < 0) // el radio es distancia por tanto es positivo, el angulo va de 0 hasta +inf 0082 return false; 0083 0084 0085 if (argname == QStringLiteral("t") && max >= 2*M_PI) 0086 return false; 0087 0088 if (argname == QStringLiteral("p") && max > M_PI) 0089 return false; 0090 0091 return AbstractFunctionGraph::setInterval(argname, min, max); 0092 } 0093 0094 SphericalSurface::SphericalSurface(const Analitza::Expression& e): AbstractSurface(e) 0095 { 0096 setInterval(QStringLiteral("t"), 0, M_PI); 0097 setInterval(QStringLiteral("p"), 0, M_PI); 0098 } 0099 0100 SphericalSurface::SphericalSurface(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v) 0101 : AbstractSurface(e, v) 0102 {} 0103 0104 QVector3D SphericalSurface::fromParametricArgs(double a, double p) 0105 { 0106 arg(QStringLiteral("t"))->setValue(a); 0107 arg(QStringLiteral("p"))->setValue(p); 0108 0109 double r = analyzer->calculateLambda().toReal().value(); 0110 0111 return sphericalToCartesian(r,a,p); 0112 } 0113 0114 void SphericalSurface::update(const QVector3D & oppositecorner1, const QVector3D & oppositecorner2) 0115 { 0116 Q_UNUSED(oppositecorner1); 0117 Q_UNUSED(oppositecorner2); 0118 buildParametricSurface(); 0119 } 0120 0121 0122 REGISTER_SURFACE(SphericalSurface)