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 #include <cstdio>
16
17 #include "chrono/geometry/ChSphere.h"
18
19 namespace chrono {
20 namespace geometry {
21
22 // Register into the object factory, to enable run-time dynamic creation and persistence
CH_FACTORY_REGISTER(ChSphere)23 CH_FACTORY_REGISTER(ChSphere)
24
25 ChSphere::ChSphere(const ChSphere& source) {
26 center = source.center;
27 rad = source.rad;
28 }
29
GetBoundingBox(double & xmin,double & xmax,double & ymin,double & ymax,double & zmin,double & zmax,ChMatrix33<> * Rot) const30 void ChSphere::GetBoundingBox(double& xmin,
31 double& xmax,
32 double& ymin,
33 double& ymax,
34 double& zmin,
35 double& zmax,
36 ChMatrix33<>* Rot) const {
37 ChVector<> trsfCenter = center;
38 if (Rot) {
39 trsfCenter = Rot->transpose() * center;
40 }
41 xmin = trsfCenter.x() - rad;
42 xmax = trsfCenter.x() + rad;
43 ymin = trsfCenter.y() - rad;
44 ymax = trsfCenter.y() + rad;
45 zmin = trsfCenter.z() - rad;
46 zmax = trsfCenter.z() + rad;
47 }
48
CovarianceMatrix(ChMatrix33<> & C) const49 void ChSphere::CovarianceMatrix(ChMatrix33<>& C) const {
50 C.setZero();
51 C(0, 0) = center.x() * center.x();
52 C(1, 1) = center.y() * center.y();
53 C(2, 2) = center.z() * center.z();
54 }
55
ArchiveOUT(ChArchiveOut & marchive)56 void ChSphere::ArchiveOUT(ChArchiveOut& marchive) {
57 // version number
58 marchive.VersionWrite<ChSphere>();
59 // serialize parent class
60 ChGeometry::ArchiveOUT(marchive);
61 // serialize all member data:
62 marchive << CHNVP(center);
63 marchive << CHNVP(rad);
64 }
65
ArchiveIN(ChArchiveIn & marchive)66 void ChSphere::ArchiveIN(ChArchiveIn& marchive) {
67 // version number
68 /*int version =*/ marchive.VersionRead();
69 // deserialize parent class
70 ChGeometry::ArchiveIN(marchive);
71 // stream in all member data:
72 marchive >> CHNVP(center);
73 marchive >> CHNVP(rad);
74 }
75
76 } // end namespace geometry
77 } // end namespace chrono
78