diff --git a/include/sch/S_Object/S_Capsule.h b/include/sch/S_Object/S_Capsule.h index 3b0b61e1..115cd5f7 100644 --- a/include/sch/S_Object/S_Capsule.h +++ b/include/sch/S_Object/S_Capsule.h @@ -12,11 +12,15 @@ namespace sch SCH_API S_Capsule(Point3 p1, Point3 p2, Scalar radius); SCH_API ~S_Capsule(); + SCH_API const Point3 & getP1() const; + SCH_API const Point3 & getP2() const; + + SCH_API Scalar getRadius() const; protected: SCH_API virtual Point3 l_Support(const Vector3& v, int& lastFeature)const; - SCH_API virtual S_ObjectType getType() const; + SCH_API virtual S_ObjectType getType() const; Point3 p1_, p2_; diff --git a/include/sch/S_Object/S_Cylinder.h b/include/sch/S_Object/S_Cylinder.h new file mode 100644 index 00000000..ecda7a26 --- /dev/null +++ b/include/sch/S_Object/S_Cylinder.h @@ -0,0 +1,33 @@ +#ifndef _S_CYLINDER_H +#define _S_CYLINDER_H + +#include + +namespace sch +{ + class S_Cylinder : + public S_ObjectNormalized + { + public: + SCH_API S_Cylinder(Point3 p1, Point3 p2, Scalar radius); + SCH_API ~S_Cylinder(); + + SCH_API const Point3 & getP1() const; + + SCH_API const Point3 & getP2() const; + + SCH_API Scalar getRadius() const; + + protected: + SCH_API virtual Point3 l_Support(const Vector3& v, int& lastFeature)const; + SCH_API virtual S_ObjectType getType() const; + + Point3 p1_, p2_; + + Vector3 normal_; + + Scalar radius_; + }; +} +#endif //_S_CYLINDER_H + diff --git a/include/sch/S_Object/S_Object.h b/include/sch/S_Object/S_Object.h index c8ab8690..aa3fcf6e 100644 --- a/include/sch/S_Object/S_Object.h +++ b/include/sch/S_Object/S_Object.h @@ -230,7 +230,8 @@ namespace sch TSTP_BV_WithPolyhedron, TPoint, TCapsule, - TCone + TCone, + TCylinder }; /*! diff --git a/include/sch/SourcesLib.cmake b/include/sch/SourcesLib.cmake index a98d4fdf..20ba521e 100644 --- a/include/sch/SourcesLib.cmake +++ b/include/sch/SourcesLib.cmake @@ -63,6 +63,7 @@ set(HEADERS_S_Object S_Object/S_Point.h S_Object/S_Capsule.h S_Object/S_Cone.h + S_Object/S_Cylinder.h ) InstallFiles(HEADERS_S_Object "S_Object") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 56c29cd8..3c3afc93 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ SET(SOURCES_S_Object S_Object/S_Point.cpp S_Object/S_Capsule.cpp S_Object/S_Cone.cpp + S_Object/S_Cylinder.cpp ) AddSourceGroup(SOURCES_S_Object "S_Object") diff --git a/src/S_Object/S_Capsule.cpp b/src/S_Object/S_Capsule.cpp index d153be76..19e66f1e 100644 --- a/src/S_Object/S_Capsule.cpp +++ b/src/S_Object/S_Capsule.cpp @@ -1,6 +1,7 @@ #include using namespace sch; + S_Capsule::S_Capsule(Point3 p1, Point3 p2, Scalar radius): p1_(p1),p2_(p2),radius_(radius) { } @@ -32,3 +33,18 @@ S_Object::S_ObjectType S_Capsule::getType() const { return S_Object::TCapsule; } + +const Point3 & S_Capsule::getP1() const +{ + return p1_; +} + +const Point3 & S_Capsule::getP2() const +{ + return p2_; +} + +Scalar S_Capsule::getRadius() const +{ + return radius_; +} diff --git a/src/S_Object/S_Cylinder.cpp b/src/S_Object/S_Cylinder.cpp new file mode 100644 index 00000000..fd6d7786 --- /dev/null +++ b/src/S_Object/S_Cylinder.cpp @@ -0,0 +1,54 @@ +#include + +using namespace sch; + +S_Cylinder::S_Cylinder(Point3 p1, Point3 p2, Scalar radius): p1_(p1),p2_(p2),radius_(radius) +{ + normal_ = p2_ - p1_; + assert(normal_.norm() != 0); + normal_.normalize(); +} + +S_Cylinder::~S_Cylinder() +{ +} + +Point3 S_Cylinder::l_Support(const Vector3& v, int& /*lastFeature*/)const +{ + Point3 d = p1_; + double dot = normal_ * v; + if (dot > 0) + { + d = p2_; + } + Vector3 proj = v - normal_ * dot; + double proj_norm = proj.norm(); + if(proj_norm != 0) + { + return d + proj * (radius_ / proj_norm); + } + else + { + return d; + } +} + +S_Object::S_ObjectType S_Cylinder::getType() const +{ + return S_Object::TCylinder; +} + +const Point3 & S_Cylinder::getP1() const +{ + return p1_; +} + +const Point3 & S_Cylinder::getP2() const +{ + return p2_; +} + +Scalar S_Cylinder::getRadius() const +{ + return radius_; +}