![]() |
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_EDGE_H 00021 #define MECHSYS_DEM_EDGE_H 00022 00023 // Std lib 00024 #include <cmath> 00025 00026 // MechSys 00027 #include <mechsys/dem/quaternion.h> 00028 00029 class Edge 00030 { 00031 public: 00032 // Constructor 00033 Edge (Vec3_t const * X0, Vec3_t const * X1); 00034 Edge (Vec3_t const & X0, Vec3_t const & X1); 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 Vec3_t const * X0; 00042 Vec3_t const * X1; 00043 Vec3_t dL; 00044 }; 00045 00046 00048 00049 00050 inline Edge::Edge (Vec3_t const * TheX0, Vec3_t const * TheX1) 00051 : X0(TheX0), X1(TheX1), dL(*X1-*X0) 00052 { 00053 } 00054 00055 inline Edge::Edge (Vec3_t const & TheX0, Vec3_t const & TheX1) 00056 : X0(&TheX0), X1(&TheX1), dL(*X1-*X0) 00057 { 00058 } 00059 00060 inline void Edge::UpdatedL() 00061 { 00062 dL = (*X1) - (*X0); 00063 } 00064 00065 inline void Edge::Draw (std::ostream & os, double Radius, char const * Color, bool BPY) 00066 { 00067 if (BPY) 00068 { 00069 Vec3_t mid = ((*X0)+(*X1))/2.0; 00070 double L = norm(dL); 00071 Vec3_t Bv(0.0,0.0,L/2.0); 00072 Vec3_t axis; 00073 axis = (*X1)-mid; 00074 axis = cross(Bv,axis); 00075 double angle; 00076 if (norm(axis)<1.0e-10) 00077 { 00078 axis =1.0,0.0,0.0; 00079 angle = 0.0; 00080 } 00081 else angle = acos(4.0*dot(Bv,(*X1)-mid)/(L*L)); 00082 os << "m = Mesh.Primitives.Cylinder(32,"<<Radius*2.0<<","<<L<<")\n"; 00083 os << "o = s.objects.new(m,'Cylinder')\n"; 00084 os << "axis = ["<<axis(0)<<","<<axis(1)<<","<<axis(2)<<"]\n"; 00085 os << "quat = Quaternion(axis,"<<angle*180/M_PI<<")\n"; 00086 os << "quat.normalize()\n"; 00087 os << "o.setMatrix(quat.toMatrix())\n"; 00088 os << "o.setLocation("<<mid(0)<<","<<mid(1)<<","<<mid(2)<<")\n"; 00089 } 00090 else 00091 { 00092 os << "cylinder { <"<<(*X0)(0)<<","<<(*X0)(1)<<","<<(*X0)(2)<<">,<"<<(*X1)(0)<<","<<(*X1)(1)<<","<<(*X1)(2)<<">,"<<Radius<<"\n pigment { color "<<Color<<" } }\n"; 00093 } 00094 } 00095 00096 #endif // MECHSYS_DEM_EDGE_H