File indexing completed on 2024-04-21 03:40:38

0001 /*************************************************************************************
0002  *  Copyright (C) 2007-2009 by Aleix Pol <aleixpol@kde.org>                          *
0003  *  Copyright (C) 2010 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>      *
0004  *                                                                                   *
0005  *  This program is free software; you can redistribute it and/or                    *
0006  *  modify it under the terms of the GNU General Public License                      *
0007  *  as published by the Free Software Foundation; either version 2                   *
0008  *  of the License, or (at your option) any later version.                           *
0009  *                                                                                   *
0010  *  This program is distributed in the hope that it will be useful,                  *
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0013  *  GNU General Public License for more details.                                     *
0014  *                                                                                   *
0015  *  You should have received a copy of the GNU General Public License                *
0016  *  along with this program; if not, write to the Free Software                      *
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0018  *************************************************************************************/
0019 
0020 #include "abstractspacecurve.h"
0021 #include "functiongraph.h"
0022 
0023 #include <cmath>
0024 #include <QVector3D>
0025 
0026 #include "analitza/analyzer.h"
0027 #include "analitza/value.h"
0028 #include "analitza/variable.h"
0029 
0030 #include "utils/mathutils.h"
0031 
0032 using namespace Analitza;
0033 
0034 using std::atan2;
0035 
0036 AbstractSpaceCurve::AbstractSpaceCurve(const Analitza::Expression& e, const QSharedPointer<Analitza::Variables>& v)
0037 : AbstractFunctionGraph(e, v)
0038 {}
0039 
0040 AbstractSpaceCurve::~AbstractSpaceCurve()
0041 {}
0042 
0043 bool AbstractSpaceCurve::addPoint(const QVector3D& p)
0044 {
0045     int count=points.count();
0046     if(count<2) {
0047         points.append(p);
0048         return false;
0049     }
0050     
0051     double angle1=std::atan2(points[count-1].y()-points[count-2].y(), points[count-1].x()-points[count-2].x());
0052     double angle2=std::atan2(p.y()-points[count-1].y(), p.x()-points[count-1].x());
0053     
0054     bool append=!isSimilar(angle1, angle2);
0055     if(append)
0056         points.append(p);
0057     else
0058         points.last()=p;
0059         
0060     return append;
0061 }
0062