1 // ============================================================================= 2 // PROJECT CHRONO - http://projectchrono.org 3 // 4 // Copyright (c) 2014 projectchrono.org 5 // All rights reserved. 6 // 7 // Use of this source code is governed by a BSD-style license that can be found 8 // in the LICENSE file at the top level of the distribution and at 9 // http://projectchrono.org/license-chrono.txt. 10 // 11 // ============================================================================= 12 // Authors: Alessandro Tasora, Radu Serban 13 // ============================================================================= 14 15 #ifndef CHC_BOX_H 16 #define CHC_BOX_H 17 18 #include <cmath> 19 20 #include "chrono/geometry/ChVolume.h" 21 22 namespace chrono { 23 namespace geometry { 24 25 /// A box geometric object for collisions and visualization. 26 27 class ChApi ChBox : public ChVolume { 28 public: 29 ChMatrix33<> Rot; ///< box rotation 30 ChVector<> Pos; ///< position of box center 31 ChVector<> Size; ///< box halflengths 32 33 public: ChBox()34 ChBox() : Rot(1), Pos(VNULL), Size(VNULL) {} 35 ChBox(const ChVector<>& mpos, const ChMatrix33<>& mrot, const ChVector<>& mlengths); 36 ChBox(const ChVector<>& mC0, const ChVector<>& mC1, const ChVector<>& mC2, const ChVector<>& mC3); 37 ChBox(const ChBox& source); 38 39 /// "Virtual" copy constructor (covariant return type). Clone()40 virtual ChBox* Clone() const override { return new ChBox(*this); } 41 GetClassType()42 virtual ChGeometry::GeometryType GetClassType() const override { return BOX; } 43 44 virtual void GetBoundingBox(double& xmin, 45 double& xmax, 46 double& ymin, 47 double& ymax, 48 double& zmin, 49 double& zmax, 50 ChMatrix33<>* bbRot = NULL) const override; 51 52 /// Computes the baricenter of the box Baricenter()53 virtual ChVector<> Baricenter() const override { return Pos; } 54 55 /// Computes the covariance matrix for the box 56 virtual void CovarianceMatrix(ChMatrix33<>& C) const override; 57 58 /// Evaluate position in cube volume 59 virtual void Evaluate(ChVector<>& pos, const double parU, const double parV, const double parW) const override; 60 61 /// This is a solid GetManifoldDimension()62 virtual int GetManifoldDimension() const override { return 3; } 63 64 /// Access the rotation of the box GetRotm()65 ChMatrix33<>* GetRotm() { return &Rot; } 66 67 /// Access the position of the barycenter of the box GetPos()68 ChVector<>& GetPos() { return Pos; } 69 70 /// Get the box half-lengths GetSize()71 ChVector<>& GetSize() { return Size; } 72 73 /// Get the x y z lengths of this box (that is, double the Size values) GetLengths()74 ChVector<> GetLengths() { return 2.0 * Size; } 75 76 /// Set the x y z lengths of this box (that is, double 77 /// the Size values) SetLengths(const ChVector<> & mlen)78 void SetLengths(const ChVector<>& mlen) { Size = 0.5 * mlen; } 79 80 // Get the 8 corner points, translated and rotated 81 ChVector<> GetP1() const; 82 ChVector<> GetP2() const; 83 ChVector<> GetP3() const; 84 ChVector<> GetP4() const; 85 ChVector<> GetP5() const; 86 ChVector<> GetP6() const; 87 ChVector<> GetP7() const; 88 ChVector<> GetP8() const; 89 90 /// Get the n-th corner point, with ipoint = 1...8 91 ChVector<> GetPn(int ipoint) const; 92 93 /// Get the volume (assuming no scaling in Rot matrix) GetVolume()94 double GetVolume() const { return Size.x() * Size.y() * Size.z() * 8.0; } 95 96 /// Method to allow serialization of transient data to archives. 97 virtual void ArchiveOUT(ChArchiveOut& marchive) override; 98 99 /// Method to allow de-serialization of transient data from archives. 100 virtual void ArchiveIN(ChArchiveIn& marchive) override; 101 }; 102 103 } // end namespace geometry 104 105 CH_CLASS_VERSION(geometry::ChBox, 0) 106 107 } // end namespace chrono 108 109 #endif 110