MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/dem/torus.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso, Raul Durand                   *
00004  * Copyright (C) 2009 Sergio Galindo                                    *
00005  *                                                                      *
00006  * This program is free software: you can redistribute it and/or modify *
00007  * it under the terms of the GNU General Public License as published by *
00008  * the Free Software Foundation, either version 3 of the License, or    *
00009  * any later version.                                                   *
00010  *                                                                      *
00011  * This program is distributed in the hope that it will be useful,      *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00014  * GNU General Public License for more details.                         *
00015  *                                                                      *
00016  * You should have received a copy of the GNU General Public License    *
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00018  ************************************************************************/
00019 
00020 #ifndef MECHSYS_DEM_TORUS_H
00021 #define MECHSYS_DEM_TORUS_H
00022 
00023 // Std lib
00024 #include <cmath>
00025 
00026 // MechSys
00027 #include <mechsys/dem/face.h>
00028 
00029 class Torus
00030 {
00031 public:
00032     // Constructor
00033     Torus (Vec3_t const * X0, Vec3_t const * X1, Vec3_t const * X2); 
00034     Torus (Vec3_t const & X0, Vec3_t const & X1, Vec3_t const & X2); 
00035 
00036     // Methods
00037     void Draw      (std::ostream & os, double Radius=1.0, char const * Color="Blue", bool BPY=false);
00038 
00039     // Data
00040     Vec3_t const * X0; 
00041     Vec3_t const * X1; 
00042     Vec3_t const * X2; 
00043     double          R;  
00044 };
00045 
00046 
00048 
00049 
00050 inline Torus::Torus (Vec3_t const * TheX0, Vec3_t const * TheX1, Vec3_t const * TheX2)
00051     : X0(TheX0), X1(TheX1), X2(TheX2)
00052 {
00053     R = norm(*X0-*X1);
00054 }
00055 
00056 inline Torus::Torus (Vec3_t const & TheX0, Vec3_t const & TheX1, Vec3_t const & TheX2)
00057     : X0(&TheX0), X1(&TheX1), X2(&TheX2)
00058 {
00059     R = norm(*X0-*X1);
00060 }
00061 
00062 inline void Torus::Draw (std::ostream & os, double Radius, char const * Color, bool BPY)
00063 {
00064     if (BPY)
00065     {
00066         throw new Fatal("Torus shape not implemented for blender");
00067     }
00068     else
00069     {
00070         Vec3_t xp,yp,zp;
00071         xp = (*X1)-(*X0);
00072         zp = (*X2)-(*X0);
00073         yp = cross(zp,xp);
00074         xp/= norm(xp);
00075         yp/= norm(yp);
00076         zp/= norm(zp);
00077         CheckDestroGiro(xp,yp,zp);
00078         Quaternion_t Q;
00079         Q(0) = 0.5*sqrt(1+xp(0)+yp(1)+zp(2));
00080         Q(1) = (yp(2)-zp(1))/(4*Q(0));
00081         Q(2) = (zp(0)-xp(2))/(4*Q(0));
00082         Q(3) = (xp(1)-yp(0))/(4*Q(0));
00083         Q = Q/norm(Q);
00084         double angle = 2*acos(Q(0));
00085         double Rmax = norm((*X0)-(*X1));
00086         double Rmin = Radius;
00087         os << "torus  { \n" << Rmax << "," << Rmin << "\n Axis_Rotate_Trans (<" 
00088            << Q(1) << "," << Q(2) << "," << Q(3) << ">," << angle*180.0/M_PI << ") \n"
00089            << "translate <" << (*X0)(0) << "," << (*X0)(1) << "," << (*X0)(2) << ">"
00090            <<"\n pigment { color "<<Color<<" } }\n";
00091     }
00092 }
00093 
00094 #endif // MECHSYS_DEM_TORUS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines