![]() |
MechSys
1.0
Computing library for simulations in continuum and discrete mechanics
|
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_CYLINDER_H 00021 #define MECHSYS_DEM_CYLINDER_H 00022 00023 // Std lib 00024 #include <cmath> 00025 00026 // MechSys 00027 #include <mechsys/dem/torus.h> 00028 00029 class Cylinder 00030 { 00031 public: 00032 // Constructor 00033 Cylinder (Torus * T0, Torus * T1, Vec3_t const * Y0, Vec3_t const * Y1); 00034 Cylinder (Torus & T0, Torus & T1, Vec3_t const & Y0, Vec3_t const & Y1); 00035 00036 // Methods 00037 void UpdatedL (); 00038 void Draw (std::ostream & os, double Radius=1.0, char const * Color="Blue", bool BPY=false); 00039 00040 // Data 00041 Torus * T0; 00042 Torus * T1; 00043 Vec3_t const *Y0; 00044 Vec3_t const *Y1; 00045 Vec3_t X0; 00046 Vec3_t X1; 00047 }; 00048 00049 00051 00052 00053 inline Cylinder::Cylinder (Torus * TheT0, Torus * TheT1, Vec3_t const * TheY0, Vec3_t const * TheY1) 00054 : T0(TheT0), T1(TheT1) 00055 { 00056 X0 = *T0->X0; 00057 X1 = *T1->X0; 00058 Y0 = TheY0; 00059 Y1 = TheY1; 00060 T0->X0 = &X0; 00061 T1->X0 = &X1; 00062 00063 } 00064 00065 inline Cylinder::Cylinder (Torus & TheT0, Torus & TheT1, Vec3_t const & TheY0, Vec3_t const & TheY1) 00066 : T0(&TheT0), T1(&TheT1) 00067 { 00068 X0 = *T0->X0; 00069 X1 = *T1->X0; 00070 Y0 = &TheY0; 00071 Y1 = &TheY1; 00072 T0->X0 = &X0; 00073 T1->X0 = &X1; 00074 } 00075 00076 inline void Cylinder::UpdatedL () 00077 { 00078 X0 = 0.5*(*T0->X1 + *Y0); 00079 X1 = 0.5*(*T1->X1 + *Y1); 00080 } 00081 00082 inline void Cylinder::Draw (std::ostream & os, double Radius, char const * Color, bool BPY) 00083 { 00084 if (BPY) 00085 { 00086 throw new Fatal("Cylinder shape not implemented for blender"); 00087 } 00088 else 00089 { 00090 double R0 = norm((*T0->X0)-(*T0->X1)); 00091 double R1 = norm((*T1->X0)-(*T1->X1)); 00092 os << "cone { \n <" << (*T0->X0)(0) << "," << (*T0->X0)(1) << "," << (*T0->X0)(2) << "> , " << R0 + Radius << "\n" 00093 << "<" << (*T1->X0)(0) << "," << (*T1->X0)(1) << "," << (*T1->X0)(2) << "> , " << R1 + Radius << "\n" 00094 << " pigment { color " << Color <<" } }\n" 00095 << "cone { \n <" << (*T0->X0)(0) << "," << (*T0->X0)(1) << "," << (*T0->X0)(2) << "> , " << R0 - Radius << "\n" 00096 << "<" << (*T1->X0)(0) << "," << (*T1->X0)(1) << "," << (*T1->X0)(2) << "> , " << R1 - Radius << "\n" 00097 << " pigment { color " << Color <<" } }\n"; 00098 } 00099 } 00100 00101 #endif // MECHSYS_DEM_CYLINDER_H