Biomechanical Joint Model
 Author: Anderson Maciel

comebezier.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Anderson Maciel                                 *
00003  *   andi.maciel@gmail.com                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  **************************************************************************/
00020 #include        <algebra/comebezier.h>
00021 #include        <algebra/comepoint3d.h>
00022 #include        <algebra/comevertex3d.h>
00023 
00024 #include        <stdio.h>
00025 
00026 
00027 //COME_Bezier::~COME_Bezier(){
00028         // Default destructor
00029         //setControlPoints( NULL );
00030 //}
00031 
00032 COME_Bezier::COME_Bezier(){
00033         
00034         COME_Vertex3D *pts = new COME_Vertex3D[4];
00035         pts[0].setXYZ( 0, 0, 0 );
00036         pts[1].setXYZ( 0, 0, 0 );
00037         pts[2].setXYZ( 0, 0, 0 );
00038         pts[3].setXYZ( 0, 0, 0 );
00039         setControlPoints( pts );
00040 }
00041 
00042 COME_Bezier::COME_Bezier( COME_Vertex3D *pts){
00043 
00044         setControlPoints( pts );
00045 }
00046                 
00047 COME_Vertex3D
00048 COME_Bezier::getControlPoint( int i ){
00049 
00050         if( i >3 ){
00051                 i = 3;
00052         }
00053         COME_Vertex3D *v = getControlPoints();
00054         return v[i];
00055 }
00056 
00057 void
00058 COME_Bezier::setControlPoint( int i, COME_Vertex3D *n ){
00059 
00060         if( i >3 ){
00061                 i = 3;
00062         }
00063         COME_Vertex3D *v = getControlPoints();
00064         v[i] = *n;
00065 }
00066 
00067 COME_Point3D
00068 COME_Bezier::getPointAsPoint( float t ){
00069 
00070         COME_Point3D    *p = new COME_Point3D();
00071         COME_Vertex3D p0 = getControlPoint(0);
00072         COME_Vertex3D p1 = getControlPoint(1);
00073         COME_Vertex3D p2 = getControlPoint(2);
00074         COME_Vertex3D p3 = getControlPoint(3);
00075         
00076         p->setX( p0.getX()*(1-t)*(1-t)*(1-t) + p1.getX()*3*t*(1-t)*(1-t) +
00077                                                  p2.getX()*3*t*t*(1-t) + p3.getX()*t*t*t );
00078         p->setY( p0.getY()*(1-t)*(1-t)*(1-t) + p1.getY()*3*t*(1-t)*(1-t) +
00079                                                  p2.getY()*3*t*t*(1-t) + p3.getY()*t*t*t );
00080         p->setZ( p0.getZ()*(1-t)*(1-t)*(1-t) + p1.getZ()*3*t*(1-t)*(1-t) +
00081                                                  p2.getZ()*3*t*t*(1-t) + p3.getZ()*t*t*t );
00082         
00083         return *p;
00084 }
00085                 
00086 COME_Vertex3D
00087 COME_Bezier::getPointAsVertex( float t ){
00088         
00089         COME_Point3D    p = getPointAsPoint(t);
00090         COME_Vertex3D   *v = new COME_Vertex3D();
00091         v->setX( p.getX() );
00092         v->setY( p.getY() );
00093         v->setZ( p.getZ() );
00094         return *v;
00095 }

Generated on Thu Dec 1 10:13:32 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5