Skip to content

Commit

Permalink
Merge pull request #35 from gergondet/topic/Cylinder
Browse files Browse the repository at this point in the history
Add S_Cylinder
  • Loading branch information
gergondet authored Aug 3, 2020
2 parents 92cf03a + eec9adc commit 86fb183
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
6 changes: 5 additions & 1 deletion include/sch/S_Object/S_Capsule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down
33 changes: 33 additions & 0 deletions include/sch/S_Object/S_Cylinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef _S_CYLINDER_H
#define _S_CYLINDER_H

#include <sch/S_Object/S_ObjectNormalized.h>

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

3 changes: 2 additions & 1 deletion include/sch/S_Object/S_Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ namespace sch
TSTP_BV_WithPolyhedron,
TPoint,
TCapsule,
TCone
TCone,
TCylinder
};

/*!
Expand Down
1 change: 1 addition & 0 deletions include/sch/SourcesLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
16 changes: 16 additions & 0 deletions src/S_Object/S_Capsule.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <sch/S_Object/S_Capsule.h>

using namespace sch;

S_Capsule::S_Capsule(Point3 p1, Point3 p2, Scalar radius): p1_(p1),p2_(p2),radius_(radius)
{
}
Expand Down Expand Up @@ -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_;
}
54 changes: 54 additions & 0 deletions src/S_Object/S_Cylinder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <sch/S_Object/S_Cylinder.h>

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_;
}

0 comments on commit 86fb183

Please sign in to comment.