00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <Cylinder.hpp>
00021 #include <TinyVector.hpp>
00022
00023 #include <cmath>
00024
00025 Cylinder::
00026 Cylinder(const TinyVector<3, real_t>& a,
00027 const TinyVector<3, real_t>& b,
00028 const real_t& r)
00029 : Shape(cylinder),
00030 __c1(a), __c2(b),
00031 __center(0.5*(a+b)),
00032 __radius (r),
00033 __radius2(r*r),
00034 __half_height(Norm(__center - __c1)),
00035 __unaryVector(1./(2.*__half_height)*(b-a))
00036 {
00037 ;
00038 }
00039
00040 Cylinder::
00041 Cylinder(const Cylinder& C)
00042 : Shape(C),
00043 __c1(C.__c1),
00044 __c2(C.__c2),
00045 __center(C.__center),
00046 __radius(C.__radius),
00047 __radius2(C.__radius2),
00048 __half_height(C.__half_height),
00049 __unaryVector(C.__unaryVector)
00050 {
00051 ;
00052 }
00053
00054 std::ostream& Cylinder::
00055 __put(std::ostream& os) const
00056 {
00057 os << "cylinder {\n" << __c1
00058 << ", " << __c2 << ", " << __radius << '\n';
00059 for (size_t i=0; i<numberOfTransformations(); i++)
00060 os << __trans[i]->povWrite() << '\n';
00061 os << "}\n";
00062 return os;
00063 }
00064
00065 inline bool Cylinder::
00066 __inShape(const TinyVector<3, real_t>& v) const
00067 {
00068 TinyVector<3, real_t> x = v-__center;
00069
00070 real_t ux = __unaryVector * x;
00071 TinyVector<3, real_t> normal (x - (ux * __unaryVector));
00072 return ((std::abs(ux) < __half_height) && (normal * normal < __radius2));
00073 }
00074
00075 ReferenceCounting<Shape> Cylinder::
00076 __getCopy() const
00077 {
00078 return new Cylinder(*this);
00079 }